Python dataframe variant code question) I want to clone row with the same value

Asked 1 years ago, Updated 1 years ago, 381 views

I want to make a data frame that looks like the top one like the bottom one. What should I do now?

https://kin.naver.com/qna/detail.naver?d1id=1&dirId=104&docId=429520356

I'm sharing the link that I attached because the image didn't go up<

python pandas numpy

2022-12-20 08:24

1 Answers

df = pd.DataFrame({'a':[1,2,3], 
                  'b':[1,2,3],
                  'c':[1,2,3],
                   'd':[1,2,3]})

res = pd.DataFrame()
for i in range(len(df)):
    res = pd.concat([res, df.iloc[[i]]])
    res = pd.concat([res, df.iloc[[i]]])
print(res)

How about this?


2022-12-20 08:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.