Turn Pandas DataFrame of strings into histogram

后端 未结 3 1566
误落风尘
误落风尘 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 03:55

    You can use pd.value_counts (value_counts is also a series method):

    In [20]: d.apply(pd.value_counts)
    Out[20]: 
       s1  s2
    a   3   3
    b   2 NaN
    c   1 NaN
    d NaN   1
    f NaN   3
    

    and than plot the resulting DataFrame.

提交回复
热议问题