Anthony1199
Anthony1199

Reputation: 21

Conversion of string to float

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.

Upvotes: 0

Views: 92

Answers (2)

user16836078
user16836078

Reputation:

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

Upvotes: 1

masoud
masoud

Reputation: 534

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)

Upvotes: 1

Related Questions