Column name class
is ignored when using to_dict(orient="records") after upgrading to 0.24
#25071
Labels
Duplicate Report
Duplicate issue or pull request
Uh oh!
There was an error while loading. Please reload this page.
Code Sample, a copy-pastable example if possible
In pandas 0.24 we encounter a bug where the dictionary key is not set correctly if the column name is
class
and we useto_dict(orient="records")
. All other orientations are ok. If we use the column nameklass
then the records orientation is also ok. Our csv file is:Then, we load the data with:
Problem description
All column names should be in the records,
class
has been replaced with_1
in the new version of pandas.Expected Output
In pandas 0.23.4 the resulting dictionary is:
This is what we'd expect. However, in pandas 0.24 we get:
Note that the
class
column name is missing from the keys in the records. This occurs in python 3.6 and 3.7 (https://travis-ci.org/comic/evalutils/builds/486831323)The column name
class
is preserved in the dictionary when using allorient="dict"
,"list"
,"series"
,"split"
or"index"
.If we change the column name to
klass
, then we do not get this problem using any orientation.It is not clear to me if this solves the problem: #24965
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: