I am learning Machine Learning from scratch from a book. I am sorry if this is a naive question or something that was discussed already here. I reviewed various other similar posts here and learned that I need to use Label Encoder to resolve this but I am not sure how to code Label Encoder and hoping someone here will help me. I really appreciate your time and your help with this.
Code:
housing_feature_engineered = pd.read_csv("todaytest.csv")
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
housing_scaled = scaler.fit_transform(housing_feature_engineered)
housing_scaled
Output:
ValueError: could not convert string to float: 'INLAND'
You can only input numeric values to the StandardScaler function. You are getting this error because the data contains string expressions.
Solution to the problem:
have an example dataframe -->>> df_example
You want to scale the ex_column_name column in the dataframe. Now you need to eliminate the string expressions contained in this df.
solution based on the example you gave (here we're deleting the lines that contain "INLAND"):
df_example=df_example[df_example["ex_column_name"]!='INLAND']
now you can scale your data :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.