DataFrame列中一个特定值的频率

huangapple go评论58阅读模式
英文:

Frequency of one specific value in a DataFrame column

问题

I am attempting to count the frequency of one specific value 'Devonport' in the column 'Ground' in a data set. I have tried to use the Groupby function and the value.counts() and it is only returning the first and last 5 unique values in the column which has a total of 173 unique values. I know there is one occurrence of 'Devonport' in the column 'Ground' because I opened the csv file and filtered on the column, but I am unable to get the function to return this in jupyter notebook.

Any help would be great! I'm very new to python - just taking a course in it now.

occur=csv.groupby(['Ground']).size().T
Ground
Aberdeen 11
Abu Dhabi 37
Adelaide 82
Ahmedabad 24
Albion 5
...
Vijayawada 1
Visakhapatnam 11
Wellington 56
Whangarei 1
Worcester 3
Length: 173, dtype: int64

print(csv.Ground.value_counts())
Sharjah 228
Dhaka 156
Sydney 154
Melbourne 147
Harare 136
...
Hove 1
Nairobi 1
Vijayawada 1
Kwekwe 1
Lucknow 1

Name: Ground, Length: 173, dtype: int64

csv['Ground'].value_counts('Devonport')
Sharjah 0.057986
Dhaka 0.039674
Sydney 0.039166
Melbourne 0.037386
Harare 0.034588
...
Hove 0.000254
Nairobi 0.000254
Vijayawada 0.000254
Kwekwe 0.000254
Lucknow 0.000254
Name: Ground, Length: 173, dtype: float64

英文:

I am attempting to count the frequency of one specific value 'Devonport' in the column 'Ground' in a data set. I have tried to use the Groupby function and the value.counts() and it is only returning the first and last 5 unique values in the column which has a total of 173 unique values. I know there is one occurrence of 'Devonport' in the column 'Ground' because I opened the csv file and filtered on the column, but I am unable to get the function to return this in jupyter notebook.

Any help would be great! I'm very new to python - just taking a course in it now.

occur=csv.groupby(['Ground']).size().T
Ground
Aberdeen         11
Abu Dhabi        37
Adelaide         82
Ahmedabad        24
Albion            5
                 ..
Vijayawada        1
Visakhapatnam    11
Wellington       56
Whangarei         1
Worcester         3
Length: 173, dtype: int64


print(csv.Ground.value_counts())
Sharjah       228
Dhaka         156
Sydney        154
Melbourne     147
Harare        136
             ... 
Hove            1
Nairobi         1
Vijayawada      1
Kwekwe          1
Lucknow         1

Name: Ground, Length: 173, dtype: int64
csv['Ground'].value_counts('Devonport')
Sharjah       0.057986
Dhaka         0.039674
Sydney        0.039166
Melbourne     0.037386
Harare        0.034588
                ...   
Hove          0.000254
Nairobi       0.000254
Vijayawada    0.000254
Kwekwe        0.000254
Lucknow       0.000254
Name: Ground, Length: 173, dtype: float64

答案1

得分: 0

这应该是您在寻找的内容:

csv['Ground'].value_counts()['Devonport']

英文:

This should be what you're looking for:

csv['Ground'].value_counts()['Devonport']

huangapple
  • 本文由 发表于 2023年5月30日 07:15:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定