Skip to content

Inconsistent integer column indexing #6546

Closed
@alexfields

Description

@alexfields

When columns have an integer as their name, indexing them becomes inconsistent:

>>> import pandas as pd
>>> df = pd.DataFrame({1:[1,1],2:[2,2],'a':['a','a']})
>>> df
   1  2  a
0  1  2  a
1  1  2  a

[2 rows x 3 columns]
>>> df[1]
0    1
1    1
Name: 1, dtype: int64
>>> df[['a',1]]
   a  1
0  a  1
1  a  1

[2 rows x 2 columns]
>>> df[[1,2]]
   2  a
0  2  a
1  2  a

[2 rows x 2 columns]

Desired behavior would be:

>>> df[[1,2]]
   1  2
0  1  2
1  1  2

[2 rows x 2 columns]

This is in pandas 0.13.1

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