pandas升级后std函数计算结果过小被四舍五入为0

在Python3.9环境中,使用`df['std']=df['mean'].rolling(n1,min_periods=1).std(ddof=0)`计算std时,遇到结果过小被四舍五入为0的问题。初步怀疑是版本过高导致。尝试降级pandas到0.20.3失败,因为不支持Python3.9。在Python3.7环境下,发现pandas导入错误,可能是升级Python版本引起。通过卸载并重新安装pandas解决了问题,最终在Python3.7下成功安装了pandas 0.25.3。

std()计算时,如果结果过小,被四舍五入为0

df['std'] = df['mean'].rolling(n1, min_periods=1).std(ddof=0)  

在这里插入图片描述
其他函数暂未出现此问题

问题定位:
(一)Python3.9环境
本地问题环境pandas版本查看:

import pandas as pd
pd.show_versions()
pd.__version__

在这里插入图片描述
估计是版本过高造成
linux服务器计算正常环境中,查询pandas版本
在这里插入图片描述

anaconda prompt中尝试版本退回

pip install pandas==0.20.3 

python3.9环境中安装失败
在这里插入图片描述
可能python版本高了不支持低版本的pandas

重新安装低版本pandas
conda install pandas=0.20.3
在这里插入图片描述
果然在3.9中不能安装

(二)Python3.7环境
切换回Python3.7

conda list

查看pandas版本:
在这里插入图片描述

import pandas

弹出:
ImportError: C extension: No module named ‘pandas._libs.tslibs.conversion’ not built. If you want to import pandas from the source directory, you may need to run ‘python setup.py build_ext --inplace --force’ to build the C extensions first.

在这里插入图片描述

估计是python版本升级过造成的问题
直接卸载了重装

conda uninstall pandas
conda install pandas

指定环境安装

$conda install -n Python3.7 pandas=0.25.3

问题解决

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

779醒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值