gpt4 book ai didi

python - 为什么 'DataFrame' 对象没有属性 'assign' ?

转载 作者:太空宇宙 更新时间:2023-11-04 00:56:16 24 4
gpt4 key购买 nike

df = pd.DataFrame({'a' : np.random.randn(10), 
'b' : np.random.randn(10),
'c' : np.random.randn(10)})
log_sum = np.log(np.abs(df["a"] + df['b'] + df['c']))
print log_sum
df.assign(log_sum=log_sum)
df.head()

我得到错误:

AttributeError: 'DataFrame' object has no attribute 'assign'

最佳答案

您必须使用旧版本的 Pandas,

assign 方法在版本 0.16.0 中引入,doc ref

你可以使用

检查你的pandas版本
import pandas
pandas.__version__

升级 Pandas -

pip install --upgrade pandas

关于python - 为什么 'DataFrame' 对象没有属性 'assign' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34959637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com