gpt4 book ai didi

python - 创建空数据框的 Pandas 错误

转载 作者:行者123 更新时间:2023-12-03 14:36:13 25 4
gpt4 key购买 nike

我尝试制作一个虚拟数据框,column_names = ["a", "b", "c"]df = pd.DataFrame(columns = column_names)我收到以下错误,以前没有发生过,我错过了什么吗?这仅在创建空数据框时发生,这是最近引入的错误。

  File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py", line 411, in __init__
mgr = init_dict(data, index, columns, dtype=dtype)
File "/usr/local/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 242, in init_dict
val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype)
File "/usr/local/lib/python3.7/site-packages/pandas/core/dtypes/cast.py", line 1221, in construct_1d_arraylike_from_scalar
dtype = dtype.dtype
AttributeError: type object 'object' has no attribute 'dtype'

Sample code

最佳答案

这是pandas==0.25.3发生的情况
更新为最新的pandas==1.2.1更新:
这是由于numpy软件包1.20.0所致,
所以我改为锁定numpy包numpy==1.19.5pandas==0.25.3如果您想知道为什么不想不必要地更新软件包,请引用此文件https://medium.com/@singhnight/how-not-to-resolve-package-related-issues-7544c3a44dc

关于python - 创建空数据框的 Pandas 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65998646/

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