unable to concat the output for multiple rows

Question:

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?

Asked By: Nithin Reddy

||

Answers:

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))))
Answered By: jezrael