How to convert data to original types when reading back data from a csv-file in an elegant way? (without using pandas!) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to convert data to original types when reading back data from a csv-file in an elegant way? (without using pandas!)

I want to retrieve data from a csv file where there are colums with unquoted numerical values. some columns have integers and some have floats. When reading back the file content I get all data in strings. In order to get back the correct type I had to do the type conversion in my code "by hand". See my example: https://code.sololearn.com/cCC5KRhdFir4/?ref=app Is there an automatic way (without using pandas) that the csv-dictreader is able to recognize the correct type of the data, without having to use the section "restore data types" in my code? Could you please give me a hint if this is possible?

12th Jul 2020, 4:32 AM
Jan Markus
0 Answers