data = {'Person': ['a','b','c','d','a','b','c','d','b','c'],
'months':['Jan','Jan','Jan','Jan','Feb','Feb','Feb','Feb','March','March'],
'income':[100,75,80,56,48,56,37,48,95,65]}
df = pd.DataFrame(data)
df.groupby(['Person'])['income'].sum()
Output:
Person
a 148
b 226
c 182
d 104
Name: income, dtype: int64
But I want to display data for only a. How can I do that?
Why use groupby if you only need a?
df.loc[df["Person"].eq("a"),"income"].sum()
#148
df[df['Person'] == 'a'].groupby(['Person'])['income'].sum()
Output
Person
a 148
Name: income, dtype: int64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With