0

I am trying to change a number in the df but the Pandas converts it to a floor number.

    A   B
0   1   4
1   2   5
2   3   6

I change a number:

df['B'][1] = 1.2

it gives:

    A   B
0   1   4
1   2   1
2   3   6

instead of:

    A   B
0   1   4
1   2   1.2
2   3   6

1 Answers1

1

Pandas has some rather complex view/copy behavior. Your syntax assigns a new value to a copy of the data, leaving the original unchanged. You can update the value in place via:

df.loc[1, "B"] = 1.2

result:

   A    B
0  1  4.0
1  2  1.2
2  3  6.0
anon01
  • 8,116
  • 7
  • 25
  • 54