I have my dtatframe and would like to present the data where the vlaues in the pivot table are simply the count of the strings, which are my columns in the pivot table:
Sample of my df:
trading_book state
A Traded Away
B Dealer Reject
C Dealer Reject
A Dealer Reject
B Dealer Reject
C Dealer Reject
A Dealer Reject
D Dealer Reject
D Dealer Reject
E Dealer Reject
Desired Result:
Traded Away Dealer Reject Done
Book
A 1 2 0
B 0 2 0
C 0 2 0
D 0 2 0
E 0 1 0
When I tried this with the following code:
Count_Row = df.shape[0] #gives number of row count
Count_Col = df.shape[1] #gives number of col count
df_Sample = df[['trading_book','state']].head(Count_Row-1)
display(df_Sample)
display(pd.pivot_table(
df_Sample,
index=['trading_book'],
columns=['state'],
values='state',
aggfunc='count'
))
I get only the trading books displaying
What needs to be done with the values and aggfunc paramaters?