-1

I have a DataFrame which contains 55000 rows and 3 columns I want to return every row as DataFrame from this bigdataframe for using it as parameter of different function. My idea was iterating over big DataFrame by iterrows(),iloc but I can't make it as DataFrame it is showing series type. How could I solve this

Kalyan
  • 1,880
  • 11
  • 35
  • 62

2 Answers2

0

I think it is obviously not necessary, because index of Series is same like columns of DataFrame.

But it is possible by:

df1 = s.to_frame().T

Or:

df1 = pd.DataFrame([s.to_numpy()], columns=s.index)

Also you can try yo avoid iterrows, because obviously very slow.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
0

I suspect you're doing something not optimal if you need what you describe. That said, if you need each row as a dataframe:

l = [pd.DataFrame(df.iloc[i]) for i in range(len(df))]

This makes a list of dataframes for each row in df

Jim Eisenberg
  • 1,490
  • 1
  • 9
  • 17