Wubek
Wubek

Reputation: 3

Python Pandas .loc function

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.

Upvotes: 0

Views: 110

Answers (1)

wasif
wasif

Reputation: 15478

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.

Upvotes: 1

Related Questions