首先将一个字典转化为DataFrame,然后以DataFrame中的列进行频次统计。
代码如下:
import pandas as pd
a={'one':['A','A','B','C','C','A','B','B','A','A'],
'tao':['B','B','C','C','A','A','C','B','C','A'],
'three':['C','B','A','A','B','B','B','A','C','D']}
b=pd.DataFrame(a)
b.describe()
b是转换后DataFrame,显示如表格:
one | tao | three | |
0 | A | B | C |
1 | A | B | B |
2 | B | C | A |
3 | C | C | A |
4 | C | A | B |
5 | A | A | B |
6 | B | C | B |
7 | B | B | A |
8 | A | C | C |
9 | A | A | D |
频次统计如表格:
one | tao | three | |
count | 10 | 10 | 10 |
unique | 3 | 3 | 4 |
top | A | C | B |
freq | 5 | 4 | 4 |