简体   繁体   中英

Pandas Pivot table aggregation

Need some help on pandas.

I have a dataframe in the format below. I need to find out what is the frequency BuySell and sum of PV across currencies.

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM