我要替换“?”楠,所以我使用了替换功能,但是没有用?我找不到原因?
import pandas as pd
import numpy as np
adult_data = pd.read_csv('adult data.txt',header=None,encoding='gb2312',delim_whitespace=True)
adult_data.columns = ['age', 'workclass', 'fnlwgt', 'education', 'education_num', 'marital_status', 'occupation', 'relationship', 'race', 'sex', 'capital_gain', 'capital_loss', 'hours_per_week', 'native_country','wage_class']
adult_data.replace('?','Na')
答案 0 :(得分:2)
您没有分配它们,因此您需要进行更改:
adult_data.replace('?','Na')
收件人:
adult_data = adult_data.replace('?','Na')
或者:
adult_data.replace('?','Na', inplace=True)