【Pandas】统计某个值的出现次数
作者:互联网
测试数据:
import pandas as pd import numpy as np df = pd.DataFrame({'key1':['a','a','b','b','a'],'key2':['one','two','one','two','one'],'data1':np.random.randn(5),'data2':np.random.randn(5)})
统计key2中各个元素的出现次数:
df['key2'].value_counts()
结果:
one 出现3次
two 出现2次
标签:randn,key2,random,two,次数,np,pd,某个,Pandas 来源: https://www.cnblogs.com/kaerxifa/p/13024763.html