Pandas df.to_stata(): 'DataFrame' object has no attribute 'dtype'
Asked Answered
C

1

8

Until now the pandas function df.to_stata() worked just fine with my datasets.

I am trying to export a dataframe that includes 29,778 rows and 37 to a Stata file using the following code:

df.to_stata("Stata_File.dta", write_index=False, version=118)

However, I receive the following error message:

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

I would really appreciate any help how to fix this.

Corybantic answered 31/12, 2021 at 11:13 Comment(3)
Do you have multiple columns with the same column name by any chance?Ranique
Actually I did have columns with identical names. Renaming those solved the problem, thanks a lot!Corybantic
@Ranique could you please your comment as an answer? I'd like to close another one where i gave the same answer as yoursMorgun
R
5

It's possible that this error arises when you have multiple columns with the same name in your dataframe

Ranique answered 10/2, 2023 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.