0

I am doing Data-Wrangling in big data-set and there are many columns containing invalid values like Unspecified, 0 Unspecified and so on so, my goal is to replace them with NaN value so that I can easily decide which column is useless or which are not by their ratio of total NaN values respective total value rows. So, I am able to replace one value at a time and I want to do this all at a time as once

here is my code for replacing a value

for columns in cutmr_df.columns.values:
    cutmr_df[columns] = cutmr_df.replace('Unspecified', np.nan)

I even have tried this too but I am getting error

for columns in cutmr_df.columns.values:
    cutmr_df[columns] = cutmr_df.replace({columns: {'Unspecified': np.nan, '0 Unspecified': np.nan}})

#---------------------ERROR--------------------------#
Cannot compare types 'ndarray(dtype=int64)' and 'str'

So, How I should do this task

Darkstar Dream
  • 1,649
  • 1
  • 12
  • 23
  • does this help: https://stackoverflow.com/a/42820982/7175713? it allows you to specify multiple values to replace using a dictionary – sammywemmy Jan 20 '20 at 04:47
  • Does this answer your question? [pandas replace multiple values one column](https://stackoverflow.com/questions/22100130/pandas-replace-multiple-values-one-column) – M_S_N Jan 20 '20 at 04:56
  • Does this answer your question? [How can I replace all the NaN values with Zero's in a column of a pandas dataframe](https://stackoverflow.com/questions/13295735/how-can-i-replace-all-the-nan-values-with-zeros-in-a-column-of-a-pandas-datafra) – Ray Jan 20 '20 at 05:14

0 Answers0