If you're looking to use pivot_table
,try:
frequency_df=df.pivot_table(index=['Dealid','PVCcy'],columns='BuySell',aggfunc='count').reset_index()
sum_df=df.pivot_table(index=['Dealid'],aggfunc='sum').reset_index()
df_final=frequency_df.join(sum_df)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.