英文:
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']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论