Turn Pandas DataFrame of strings into histogram

后端 未结 3 1538
误落风尘
误落风尘 2020-12-31 03:40

Suppose I have a DataFrame of created like this:

import pandas as pd
s1 = pd.Series([\'a\', \'b\', \'a\', \'c\', \'a\', \'b\'])
s2 = pd.Series([\'a\', \'f\',         


        
3条回答
  •  离开以前
    2020-12-31 04:04

    I would shove the Series into a collections.Counter (documentation) (You might need to convert it to a list first). I am not a pandas expert, but I think you should be able to fold the Counter object back into a Series, indexed by the strings, and use that to make your plots.

    This is not working because it is (rightly) raising errors when it tries to guess where the bin edges should be, which simply makes no sense with strings.

提交回复
热议问题