0

I have dataframe column (df) which I am trying to replace 999 values with blank. The head of the unadjusted column looks like:

Name: IntValue, dtype: int32
0    999
1     50
2     50
3     55
4     58

I would like the adjusted column to be adjusted to look like:

Name: IntValue, dtype: int32
0    
1     50
2     50
3     55
4     58

I am using:

rawDatabase[newFieldTrunc].replace(999, "")

But it's not changing the columns data at all.

3 Answers 3

1

Because you are replacing over a copy of the Series, not the actual Series.

rawDatabase[newFieldTrunc].replace(999, "", inplace=True)

Or

rawDatabase[newFieldTrunc] = rawDatabase[newFieldTrunc].replace(999, "")

PS: It is advised to use Python native None or np.nan as a placeholder for blanks instead of a blank text "".

Sign up to request clarification or add additional context in comments.

Comments

0

To alter the DataFrame inplace, you need to set the inplace argument to True:

rawDatabase[newFieldTrunc].replace(999, "", inplace=True)

Comments

0

As alternative to the previous answers:

 rawDatabase[newFieldTrunc] = rawDatabase[newFieldTrunc].replace(999, "")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.