Home > other >  unable to concat the output for multiple rows
unable to concat the output for multiple rows

Time:08-09

I have a dataframe which is like below

enter image description here

If i write a code like below

df.iloc[0]

enter image description here

And if i write code like below

df.iloc[3]

enter image description here

I want to concat all the df.iloc[0], df.iloc1, df.iloc2 untill whatever the max rows are are present. But with the help of for loop i'm unable to. Can anyone help me with this?

CodePudding user response:

Use concat with comprehension:

df1 = pd.concat((df.loc[i] for i in df.index))

Or:

df1 = pd.concat((df.iloc[i] for i in range(len(df.index))))
  • Related