0

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.

BigBen
  • 46,229
  • 7
  • 24
  • 40
Geordie D
  • 21
  • 5
  • 2
    Did you try [reading the documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) for `read_csv`? In particular, does the `dtype` parameter seem useful? – Karl Knechtel Aug 19 '22 at 14:13
  • Does this answer your question? [How do I parse a string to a float or int?](https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int) – isle_of_gods Aug 19 '22 at 14:14
  • @isle_of_gods Thank you very much. Everything works smoothly – Geordie D Jan 05 '23 at 09:43

2 Answers2

1

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)

masoud
  • 535
  • 3
  • 16
1

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']]