[英]Get frequency of value in DataFrame column in Python
Part of a homework question I got: I need to get the frequency of a unique value inside a column from a DataFrame, using Pandas. But, I must use crosstab()
function!我得到的作业问题的一部分:我需要使用 Pandas 从 DataFrame 获取列内唯一值的频率。但是,我必须使用
crosstab()
函数!
Here is part of the DataFrame这是DataFrame的一部分
And I want to get the frequency (in percentage) of the value 'E'
in the 'color'
column.我想获得
'color'
列中值'E'
的频率(百分比)。
Here is how the result should look like:结果应该是这样的:
And this is what I have so far:这就是我到目前为止所拥有的:
What am I doing wrong?我究竟做错了什么? How can I get it the same?
我怎样才能得到它一样?
pd.crosstab("", dataframe[], normalize=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.