DataFrame列中一个特定值的频率

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

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.

  1. occur=csv.groupby(['Ground']).size().T
  2. Ground
  3. Aberdeen 11
  4. Abu Dhabi 37
  5. Adelaide 82
  6. Ahmedabad 24
  7. Albion 5
  8. ..
  9. Vijayawada 1
  10. Visakhapatnam 11
  11. Wellington 56
  12. Whangarei 1
  13. Worcester 3
  14. Length: 173, dtype: int64
  15. print(csv.Ground.value_counts())
  16. Sharjah 228
  17. Dhaka 156
  18. Sydney 154
  19. Melbourne 147
  20. Harare 136
  21. ...
  22. Hove 1
  23. Nairobi 1
  24. Vijayawada 1
  25. Kwekwe 1
  26. Lucknow 1
  27. Name: Ground, Length: 173, dtype: int64
  28. csv['Ground'].value_counts('Devonport')
  29. Sharjah 0.057986
  30. Dhaka 0.039674
  31. Sydney 0.039166
  32. Melbourne 0.037386
  33. Harare 0.034588
  34. ...
  35. Hove 0.000254
  36. Nairobi 0.000254
  37. Vijayawada 0.000254
  38. Kwekwe 0.000254
  39. Lucknow 0.000254
  40. Name: Ground, Length: 173, dtype: float64

答案1

得分: 0

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

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

英文:

This should be what you're looking for:

  1. 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:

确定