Open DrPepper8888 opened 8 months ago
# 使用groupby和size方法来计算每个顾客持仓的货币对数量 df_holdings_breadth = df.groupby('cust_id').size().reset_index(name='holdings_breadth')
df['total_holding_time'] = df[['holding_time_1', 'holding_time_2', 'holding_time_3']].sum(axis=1) # 然后,我们计算每个客户的持仓时间的平均值 avg_holding_time_per_cust = df.groupby('cust_id')['total_holding_time'].mean().reset_index()