'Change object data type to float data type
I read the .cvs file, which dataframe is named "df". But because I want to focus in one row I renamed my dataframe to "br". My problem is that I'm trying to convert the object columns that have percentage (Bronx %, Brooklyn%, Manhattan%, Queens%, State Island%) into float. How do I change to a float data type?
df = pd.read_csv('Education.csv')
br = df.loc[[15]]
br['Bronx %'].dtype
dtype('O')
Solution 1:[1]
Use the float() function -
my_string = "193.2341412"
my_float = float(my_string)
print(my_float)
>>> 193.2341412
print(type(my_float))
>>> <* FLOAT >
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alien_jedi |

