python 平均数函数_python-平均函数,不包括Pandas DataFrame中每一行的值

有没有一种简单的方法来计算pandas DataFrame中每一列的平均值,并且为每一行排除特定值?下面每一行中的x标记了每次迭代中要从计算中排除的值:

a b a b a b

0 1 2 0 x x 0 1 2

1 2 4 first loop 1 2 4 second loop 1 x x etc.

2 3 6 ---> 2 3 6 ---> 2 3 6 --->

3 4 8 3 4 8 3 4 8

4 5 10 4 5 10 4 5 10

____________ _____________

col_avg: 3.5 7.0 col_avg: 3.25 6.5

Using only 4 values at each iteration, as the "x" is excluded from data set

产生一个新的DataFrame

a_x b_x

0 3.5 7.0

1 3.25 6.5

2 3.0 6.0

3 2.75 5.5

4 2.5 5.0

谢谢

/ N

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值