Hi,
I have below DataFrame:
data = {'Name':['Tom', 'nick', 'krish', 'jack'],
'Age':['Fail', 'Pass', 'Pass', 'Fail']}
I want to get the count of each unique item under column "Age"(for example here Pass & Fail). Finally summarize to:
I have below DataFrame:
data = {'Name':['Tom', 'nick', 'krish', 'jack'],
'Age':['Fail', 'Pass', 'Pass', 'Fail']}
I want to get the count of each unique item under column "Age"(for example here Pass & Fail). Finally summarize to:
Labels values Fail 2 Pass 2I use below code, but I could get the count, but could not be able to arrange to the table as shown above.
#%%: import pandas as pd # intialise data of lists. data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':['Fail', 'Pass', 'Pass', 'Fail']} # Create DataFrame df = pd.DataFrame(data) data_cnt=df.groupby('Age').count()