Skip to content

BUG: setting float on integer column with DataFrame.at casts the value to integer. #37477

Closed
@erfannariman

Description

@erfannariman
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

In [5]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [3, 4, 5]})

In [6]: df
Out[6]: 
   A  B
0  1  3
1  2  4
2  3  5

In [7]: df.at[1, 'B'] = 1.2

In [8]: df
Out[8]: 
   A  B
0  1  3
1  2  1
2  3  5

Problem description

DataFrame.at sets the new value but casts it to integer.

Expected output

This is not the issue with loc:

In [9]: df.loc[1, 'B'] = 1.2

In [10]: df
Out[10]: 
   A    B
0  1  3.0
1  2  1.2
2  3  5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions