I am interested in separating this data frame into 20 smaller dataframes based on the frequency of entries in column B. B has numerical entries, some of these are repeated several times, as can be seen below.
A (index) B (Column of interest)
0 1
1 2
2 2
3 2
4 3
... ...
25643 5238
25644 5238
25645 5238
25646 5238
25647 5238
I am looking to have one data frame for each frequency: 1-10, 11-20, 21-30,...., 191-200. Meaning, 1-10 dataframe contains all the entries from B that appear between 1 and 10 times throughout this dataframe. Similarly, the 11-20 dataframe contains all the entries that appear 11 and 20 times throughout the dataframe.
In the end, I should have 20 dataframes, all of which split this main dataframe.
All I've been able to do is find the distinct number of entries in my desired entries from Column B that correspond to these freeuqncies using the following code:
df.loc[(df['B'] > 0) & (df['B'] < 11)]
df.loc[(df['B'] > 10) & (df['B'] < 21)]
...
df.loc[df['B'] > 190) & (df['B'] < 201)
I have been thinking of using the groupby() function, however, I haven't found a way to group the column entries based on frequency.
Any help is appreciated!