close

[Solved] IndexError: single positional indexer is out-of-bounds

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to read dataset’s column But I am facing following error IndexError: single positional indexer is out-of-bounds in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How IndexError: single positional indexer is out-of-bounds Error Occurs?

I am trying to read dataset’s column But I am facing following error.

IndexError: single positional indexer is out-of-bounds

Here is my code

Y = Dataset.iloc[:,17].values

How To Solve IndexError: single positional indexer is out-of-bounds Error ?

  1. How To Solve IndexError: single positional indexer is out-of-bounds Error ?

    To Solve IndexError: single positional indexer is out-of-bounds Error Here problem is column that you are trying is does not exist. For example try to index the eleventh column which doesn't exist will cause in error.

  2. IndexError: single positional indexer is out-of-bounds

    To Solve IndexError: single positional indexer is out-of-bounds Error Here problem is column that you are trying is does not exist. For example try to index the eleventh column which doesn't exist will cause in error.

Solution 1: column that you are trying is does not exist

Here problem is column that you are trying is does not exist. Here is my example.

import pandas as pd

df = pd.DataFrame({'Name': ['Mark', 'Laura', 'Adam', 'Roger', 'Anna'],
                   'City': ['Lisbon', 'Montreal', 'Lisbon', 'Berlin', 'Glasgow'],
                   'Car': ['Tesla', 'Audi', 'Porsche', 'Ford', 'Honda']})

Output will be like this.

    Name      City      Car
0   Mark    Lisbon    Tesla
1  Laura  Montreal     Audi
2   Adam    Lisbon  Porsche
3  Roger    Berlin     Ford
4   Anna   Glasgow    Honda

Now For example try to index the eleventh column which doesn’t exist will cause in error.

df.iloc[:, 10] # there is obviously no 11th column

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read