Hopefully a simple request.
I'm finding that when I build a DataFrame and set the column datatypes and then export it to csv it is doing a conversion on the datatype of a numerical string to an integer.
Such as a value might be "0000" and the csv ends up with value 0. But I need it to retain the number of characters in the string and save the csv as "0000".
Anyone know of a way to retain the string rather than the converted datatype?
Setting the datatype after import doesn't solve the issue (before anyone tells me I can set it on/after import), as it causes the issue that when converting the integer to a string you have to also configure the leading 0s on every import as well, which is not optimal.
Hoping I'm overlooking something simple.
(EDIT) oh and my export line is just a simple export which is why it might be I'm just not realising the argument that needs to be provided.
df.to_csv("Test.csv", index=False)
See Question&Answers more detail:os