I can return the frequency of all columns in a nice dataframe with a total column.
for column in df:
df.groupby(column).size().reset_index(name="total")
Count total
0 1 423
1 2 488
2 3 454
3 4 408
4 5 343
Precipitation total
0 Fine 7490
1 Fog 23
2 Other 51
3 Raining 808
Month total
0 1 717
1 2 648
2 3 710
3 4 701
I put the loop in a function, but this returns the first column "Count" only.
def count_all_columns_freq(dataframe_x):
for column in dataframe_x:
return dataframe_x.groupby(column).size().reset_index(name="total")
count_all_columns_freq(df)
Count total
0 1 423
1 2 488
2 3 454
3 4 408
4 5 343
Is there a way to do this using slicing or other method e.g. for column in dataframe_x[1:]: