1

I pull from a SQL database which sometimes looks like this.

A B C D _ E F _ G

So when I put it into a data frame and print it as a CSV I want it to look like

A, B, C, D, , E, F, , G

But instead it looks like

A, B, C, D, E, F, G

So when I have a full row and then a row with some data missing, if I put it into an excel sheet and deliminate by comma, they do not match up properly.

df5 = pd.DataFrame(SQLQuery)
df5.to_csv(r'finalResults.csv', index = False)

1 Answer 1

1

You should use df5 = pd.read_sql_query(SQLQuery, connectionString)

Then if you do df5.to_csv or .to_excel it will properly format

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.