for col in obj_cols:
data[col].fillna('-1', inplace = True)
data[col] = data[col].map(dict(zip(data[col].unique(),list(range(data[col].nunique())))))
print(col+' over...')
3,绘制和保存分布
train = data[data.label!=-1]
test = data[data.label==-1]
train = train.dropna()
test = test.dropna()
for i in data.columns:
try:
g = sns.kdeplot(train[i], color="Red", shade = True)
g = sns.kdeplot(test[i], ax =g, color="Blue", shade= True)
g.set_xlabel(i)
g.set_ylabel("Frequency")
g = g.legend(["train","test"])
tmp = 'train_test_' + i
plt.savefig('./train_test/%s.jpg'%tmp)
plt.show()
print('plot over:%s'%i)
except:
print('jump %s'%i)
for col in obj_cols: data[col].fillna('-1', inplace = True) data[col] = data[col].map(dict(zip(data[col].unique(),list(range(data[col].nunique()))))) print(col+' over...')