2

So something really weird is happening when I try editing :

In [119]: print(GDP.iloc[1][0])
Out [119]: Andorra

When I try to edit it with .iloc and query it again this happens:

In [120]: GDP.iloc[1][0]="Cats"
          print(GDP.iloc[1][0])
Out [120]: Andorra

I remember reading that .iloc may call a copy or an image depending on the numpy type. Anyway to fix this or is there other way I should be editing my data? Thanks.

Fernando Chu
  • 359
  • 3
  • 14
  • 2
    Try `GDP.iloc[1,0]=`? `GDP.iloc[1][0]` is probably making a copy thus rendering it not editable. – Divakar May 09 '17 at 17:56

1 Answers1

2

It is best to avoid chaining assignments in pandas, see this SO post which refers to this Pandas doc about chaining assignments

Whenever, you have "][" in pandas it is generally bad and should be rewritten.

It is best written as Divakar suggests:

GDP.iloc[1,0]="Cats"
Community
  • 1
  • 1
Scott Boston
  • 147,308
  • 15
  • 139
  • 187