Home > Software design >  Conversion of string to float
Conversion of string to float

Time:08-22

I read from the following file my data, and create a table.

         tracks=pd.read_csv('C:\\Users\\demet\\Desktop\\Internship\\scripts\\tracks-rainy.csv')

Yet when I print for instance an element instead of obtaining a float a get a string.

         print(tracks.iloc[track_id][3][0])

What should I add to my project.

CodePudding user response:

You can try:

tracks=pd.read_csv('C:\\Users\\demet\\Desktop\\Internship\\scripts\\tracks-rainy.csv', dtype={'track_id':'Float64'})

Which tell pandas to interpret the column as Float. (As Karl Knechtel said)

CodePudding user response:

If you do not want to initiate the conversion when reading the csv file, you can always do list comprehension with a float conversion.

tracks['track_id'] = [float(i) for i in tracks['track_id']]
  • Related