1

I am trying to add a value at a particular row and column but it is giving weird results:

enter image description here

After this when I again try to add a different value to same column, it is added correctly!!!! a

Chandan Malla
  • 481
  • 5
  • 14
  • 1
    Please do not post code/data/error messages as images. Post the text directly here at SO. I suggest also reading [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Mr. T Dec 28 '20 at 18:12

1 Answers1

1

In the first scenario, .at tries to find row with index 0 and column label ('00', '00'). When it is not found, it creates a new row with index 0 and adds a new column '00'. It treats the tuple as a list of columns and assigns value 34323 to each column.

In the second scenario, the row index and column label exist, hence the value is assigned to the respective cell.

For the first scenario, you can use the following for assignment-

df.at[k, [some_variable]] = 34323

This will treat some_variable as a single column.

Shradha
  • 2,232
  • 1
  • 14
  • 26