0

I have seen several posts giving solutions to counting frequencies of either numbers or categories by column in a pandas data frame, such as this. If I have a data frame n x m having only numeric, I want to do the same for the entire data frame, how do I do that without first flattening it into one column/vector? Thanks,

Tristan Tran
  • 1,351
  • 1
  • 10
  • 36

1 Answers1

1

You can use numpy for this:

values, counts = np.unique(df, return_counts=True)

for v, c in zip(values, counts):
    print(v, c)

for dataframe like

   a  b
0  1  2
1  1  3

it will output

1 2
2 1
3 1
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48