When I try to get my dataframe out of the csv file the type of the data changed. Is there a way I can avoid this?
CSVs are text files so don't inherently contain meta-data like datatypes.
When you're opening the CSV you've saved, Python/Pandas is interpreting what it thinks the datatypes are - presumably it's getting it slightly wrong compared to what you want (this is what's happening rather than your CSV being saved with the wrong datatypes).
Pandas 'read_csv' has a 'dtype' argument which will take a dictionary of column types. This should let you specify what data types you'd like. I'd suggest reading through the function documentation here.
1.4m articles
1.4m replys
5 comments
57.0k users