【发布时间】:2021-02-01 19:02:51
【问题描述】:
我尝试制作一个虚拟数据框,
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'
【问题讨论】:
-
能否提供完整代码?
-
您的代码中还有什么内容?
-
这就是我正在尝试的,在终端@Epsi95
-
您使用哪个版本的熊猫?我无法重现 pandas 1.1.4 中的错误。
-
也许当你尝试更新你的熊猫时它可以解决你的问题。