Datatypes

I need help in coverting datatypes, when I coverting each column of the dataframe using;
salaries[‘BasePay’].astype(float)
am getting this;
ValueError: could not convert string to float: ‘Not Provided’
if i pass the the datatypes while importing the data like;
import pandas as pd
salaries=pd.read_csv(‘Salaries.csv’, dtype={‘BasePay’: float})
still getting;
ValueError: could not convert string to float: ‘Not Provided’
what should I do

Hi,
You have value(s) of ‘Not Provided’ in your Base Pay column, which can’t be directly converted to a float so it raises an error.
You need to make a decision on what to do with them, for instance;

-Change it to a value(s)
-Drop the rows that contain them
-Ignore them

It will depend on what you’re using the data for.

Hope that helps.

2 Likes

Thank you so much, you have helped me progress in my first data science portifolio project.

1 Like