-1

I want to replace the "?" with nan so I use the replace function, however it did not work? I can not find the reason?

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')
Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58

1 Answers1

2

You did not assign them, so you would need to change:

adult_data.replace('?','Na')

To:

adult_data = adult_data.replace('?','Na')

Or:

adult_data.replace('?','Na', inplace=True)
U13-Forward
  • 69,221
  • 14
  • 89
  • 114