我有以下分类数据:
['Self employed', 'Government Dependent',
'Formally employed Private', 'Informally employed',
'Formally employed Government', 'Farming and Fishing',
'Remittance Dependent', 'Other Income',
'Don't Know/Refuse to answer', 'No Income']
如何将它们放入垃圾箱中,以便:
['Government Dependent','Formally employed Government','Formally
employed Private'] = 0
['Remittance Dependent', 'Informally employed','Self employed','Other Income'] = 1
['Dont Know/Refuse to answer', 'No Income','Farming and Fishing'] = 2
我已经知道把数字数据放进分类箱……反过来可以吗
TRAIN = pd.read_csv("Train_v2.csv")
TRAIN['job_type'].unique()
output:
array(['Self employed', 'Government Dependent',
'Formally employed Private', 'Informally employed',
'Formally employed Government', 'Farming and Fishing',
'Remittance Dependent', 'Other Income',
'Dont Know/Refuse to answer', 'No Income'], dtype=object)
首先创建字典,通过交换进行更改,最后使用^{} :
如果只有} 工作,但如果有许多组,则其复杂且缓慢:
0
、1
和NaN
的输出也在^{如果
np.where
不属于类别0或类别1或类别2,则可以执行np.where
并使np.nan
成为值。有关np.where
{a1}的更多资源:相关问题 更多 >
编程相关推荐