I have pandas data frame and want to create 4 other data frames from it, based on distinct values in one column (Let say column A in df). The shape of the data frame called df is (77572, 36). I have a total of 1714 distinct values in column A. The end result should give a total of 4 data frames, with shapes (500, 36).
If we use df['A'].unique()
or df.groupby['A']
we get the desirable result structure, but the type of the result is pandas.core.groupby.generic.DataFrameGroupBy
for groupby() method, thus make it imposible to furter slice the df like for example:
df1 = df.iloc[:500,:]
df2 = df.iloc[501:1000,:]
df3 = df.iloc[1001:1500,:]
df4 = df.iloc[1501:,:]
How to generate new pandas DataFrame object with shape (1714, 36) - 1714 being distinct values in column A, and make 4 additional data frames from it?