如何使用 python pandas 在由几列分组的列中找到元素的计数?
我有以下 csv 文件结构:
'Country' 'City' 'Year' 'Month' 'Value' 'Street_Code'
USA New York 1971 jan 0.0 1
USA New York 1971 feb 23.5 1
USA New York 1971 mar 10.2 1
USA Florida 1971 jan 0.0 1
USA Florida 1971 feb 0.0 1
USA Florida 1971 mar 0.0 1
USA New York 1971 jan 0.0 2
USA New York 1971 feb 15.0 2
USA New York 1971 mar 7.6 2
USA Florida 1971 jan 0.0 2
USA Florida 1971 feb 0.0 2
USA Florida 1971 mar 2.3 2
我想'value'
通过分组来计算零(0.0)的数量'Country'
, 'City'
, 'Year'
& 'Street Code'
。
到目前为止,我已经尝试过了;
import pandas as pd
data = pd.read_csv('country_details.csv')
count_data = data[data['Value'] == 0.0] # I'm filtering the data. I don't think this is the right way of doing it
grouped = count_data.groupby(['Country','Year','Month','Street_Code']) # I'm stuck here