Pandas中自带计数函数value_counts(),但是并不能解决我们遇到的问题。
我们有这样一组数据,72*72的维度,需要统计每一列数据中的元素大于0.5的个数。
解决方法
用到pandas
库
df[col_name][df[col_name]>num].count()
df为DataFrame对象,col_name为某列的名称,num为需要比较的值
回到上面的例题,我的解决方法为:
counts=[]
for i in range(72):
count=frame.iloc[:,i][frame.iloc[:,i]>0.6].count()
counts.append(count)
counts,len(counts)
最后的结果符合要求!共计72条数据!