I am trying to get the count of 'Yes' and 'No' in separate columns using pandas group-by. Below is my sample input code.
import pandas as pd
input_data = {'id': [1,1,1,2,2,3], 'status': ['Yes', 'No', 'Yes', 'No', 'No', 'Yes']}
df = pd.DataFrame(input_data)
df
Here's my expected output:
Where 'status_Yes' and 'status_No' are representing the counts of Yes and No for respective ids.
I tried the following code:
pd.DataFrame((df['status'] == 'Yes').groupby(df['id']).sum()).reset_index()
where the status column is showing the counts of 'Yes' only.
Is there any other way to get the expected out using pandas group-by.