Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

507
Views
Pandas Error for creating an emptydataframe

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'

Sample code

over 4 years ago · Hanz Gallego
4 answers
Answer question

0

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

over 4 years ago · Hanz Gallego Report

0

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

over 4 years ago · Hanz Gallego Report

0

pandas version was the problem in my case.

It should work if you shift from

pandas==0.25.3 into pandas==1.2.3

over 4 years ago · Hanz Gallego Report

0

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)
over 4 years ago · Hanz Gallego Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!