0

i have some question. I want to change one value in a column. Is there any diff in output between this two examples?

wards.loc[wards['ward'] == '1', ['ward']] = '61'

&

wards.loc[wards['ward'] == '1'] = '61'

Thanks for replies.

1
  • You can also simply do: wards['ward'] = wards['ward'].replace('1', '61') This is simpler in my opinion, but they are just about the same amount of characters, and I think a direct replace would be more performant. Commented Dec 5, 2020 at 10:09

1 Answer 1

1

Yes, there is difference.

  • The first one will select all columns of the dataframe where the criteria has matched.
  • And the second one will select only the ward column as a dataframe where the criteria has matched.
  • But if you not use [] then it will get a series.
  • Also these are don't different if ward is the only column in dataframe.
Sign up to request clarification or add additional context in comments.

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.