Here's a code I wrote for pre-processing a data set. It works
import numpy as np
import pandas as pd
from sklearn import svm
%matplotlib inline
import matplotlib.pyplot as plt
from sklearn.impute import SimpleImputer
import seaborn as sns; sns.set(font_scale=1.2)
stock=pd.read_csv("C:/Users/Dulangi/Downloads/winequality-red.csv")
stock.head()
X= stock.iloc[:,0:5].values
y= stock.iloc[:,5].values
g=sns.lmplot('alcohol','quality',data=stock,height=7, truncate=True, scatter_kws={"s":100})
imputer = SimpleImputer( strategy = "mean")
imputer = imputer.fit(X[:,1:2])
imputer.fit_transform(X[:,1:2])
imputer = imputer.fit(X[:,4:5])
imputer.fit_transform(X[:,4:5])
I want to know what if i have both strings and numeric data in one column, how to pre-process such data to have all numeric data?
NaNs
, give it an identifying number (e.g.-1
), or something else? $\endgroup$df[0] = df[0].apply(lambda x: int(x))
work for you?0
is the name of the column $\endgroup$