pandas高级操作总结

这篇博客总结了pandas的高级操作,包括列的分位数计算,多重聚合功能,如何使用自定义函数进行聚合和在聚合后的dataframe上应用函数。还探讨了移动平均、数据组基本信息、遍历、最大互信息数计算、皮尔逊相关系数以及如何自定义聚合和设置值的方法,如使用字典进行设置。
摘要由CSDN通过智能技术生成

1.pandas中的列的分位数

# 查看列的分位数
import pandas as pd
# set columns type
my_df['col'] = my_df['col'].astype(np.float64)

# computations for 4 quantiles : quartiles
bins_col = pd.qcut(my_df['col'], 4)
bins_col_label = pd.qcut(my_df['col'], 4).labels

2.多重聚合(组函数)

# 多重聚合(组函数)
# columns settings
grouped_on = 'col_0'  # ['col_0', 'col_2'] for multiple columns
aggregated_column = 'col_1'

### Choice of aggregate functions
## On non-NA values in the group
## - numeric choice :: mean, median, sum, std, var, min, max, prod
## - group choice :: first, last, count
# list of functions to compute
agg_funcs = ['mean', 'max']

# compute aggregate values
aggregated_values = my_df.groupby(grouped_on)[aggregated_columns].agg(agg_funcs)

# get the aggregate of group
aggregat
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值