Skip to content

ERR: Raise a better message when mixing positional and label indexing in loc/iloc #25753

Closed
@LucaPaterlini

Description

@LucaPaterlini

Code Sample, a copy-pastable example if possible

import numpy as np

data = DataFrame(np.arange(16).reshape((4, 4)),
    index=['Ohio', 'Colorado', 'Utah', 'New York'],
    columns=['one', 'two', 'three', 'four'])

data[data < 5] = 0


print(data.iloc[['Colorado', 'Utah'], [3, 0, 1]])
# .ix is deprecated. Please use
# .loc for label based indexing or
# .iloc for positional indexing


print(data.iloc[['Colorado', 'Utah'], [3, 0, 1]])
#TypeError: cannot perform reduce with flexible type

print(data.loc[['Colorado', 'Utah'], [3, 0, 1]])
#KeyError: "None of [Int64Index([3, 0, 1], dtype='int64')] are in the [columns]"

Problem description

I followed the suggesion to move the ix to iloc and this is what I have got
I have used python 3.7.2 on an elemntary os 18.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasIndexingRelated 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