0

I have a .dta file that I want to convert to CSV format. Here is my code:

df = pd.read_stata('file location', convert_categoricals=False)
df.to_csv('new file')

However when I convert the file, it shifts all my data to the right and includes a new ID value under the first column.

e.g.

What my data should look like in CSV format:

Age Weight Height
22  23     24
33  NaN    34 
44  NaN    0

What it ends up looking like:

Age Weight Height
0   22     23     24
1   23     NaN    34 
2   44     NaN    0

As you can see it shifts everything to the right and places an incrementing index in the age column.

I am looking for any solution that can help me efficiently shift the data to where it is meant to be or a way to convert to CSV without causing this problem.

Joseph
  • 253
  • 1
  • 8

0 Answers0