简体   繁体   English

列数组上的 Value_counts()

[英]Value_counts() on array of columns

I have array = ['T4U measured','FTI measured', 'lithium'] and need to do value_counts on all these columns.我有数组 = ['T4U 测量','FTI 测量','锂'] 并且需要对所有这些列进行 value_counts。

something like df[array].value_counts(), which show histogram of values in columns df[array].value_counts() 之类的东西,它显示列中值的直方图

You can use the DataFrame.hist method:您可以使用DataFrame.hist方法:

for i in range(0, len(array)):
    df[array[i]].hist(bins=df[array[i]].value_counts())

This method works on the whole dataframe, in case you don't want to call it on each column separately.此方法适用于整个数据框,以防您不想分别在每一列上调用它。 But in that case, you cannot adjust the number of bins to each column.但在这种情况下,您无法调整每列的 bin 数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM