I tried making a dummy dataframe,
column_names = ["a", "b", "c"]
df = pd.DataFrame(columns = column_names)
I am getting the following error, this was not happening before, am I missing something. This is only happening on the creation of an empty dataframe, is this a recently introduced bug.
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'
If for some reason you don't/can't upgrade numpy/pandas, an alternative way to fix this is by specifiying the dtype when creating the DataFrame. For example:
column_names = ["a", "b", "c"]
df = pd.DataFrame(columns = column_names, dtype=object)
pandas version was the problem in my case.
It should work if you shift from
pandas==0.25.3 into pandas==1.2.3
This was happening with pandas==0.25.3
Updated to the latest pandas==1.2.1
UPDATE:
This was due to a numpy package 1.20.0,
so I locked the numpy package instead, numpy==1.19.5, pandas==0.25.3
Reference this if you want to know why you don't want to update packages unnecessarily, https://medium.com/@singhnight/how-not-to-resolve-package-related-issues-7544c3a44dc
happening due to numpy==1.20.0, and resolve with numpy==1.19.5.
pandas version may not relevant, in my case, pandas==1.0.4