I am aware of:
for index, row in dataframe.iterrows():
But I wish for each row to be its own dataframe instead of the type series. How would I go about doing this? Do I have to convert it or this a better way of looping through?
I am aware of:
for index, row in dataframe.iterrows():
But I wish for each row to be its own dataframe instead of the type series. How would I go about doing this? Do I have to convert it or this a better way of looping through?
If you need each row as DataFrame
for i in range(len(df)):
df.iloc[[i],:]
for index in df.index :
df.loc[[index],:]
I would suggest loading the dataframes into a list of dataframes, then you can access them individually.
df_list = []
for index, row in df.iterrows():
df_list.append(df[index:index+1])
then you can access the list df_list[0]
for example
Depends on the usage. From what I could guess (a function that only applies on a DataFrame), you have two options :
convert your row to a frame :
df_row = row.to_frame()
group your df (doing something as silly as resetting its index to have uniquely dataFrames of only 1 row), and apply the function to it :
df.reset_index().groupby('index_0').apply(func)