The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Issue with range in loc[]

Issue with range in loc[]

0
Votes
1
Answer

When I am giving loc[:,1:14] it throws an error 

"TypeError: cannot do slice indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [1] of <class 'int'>"

But loc[:,[1,2,3]] is working.

Can you please help me with it?
1 Answer

365 Team
0
Votes

Hey Shrinidhi, 
 
A general rule to remember is the number of squared brackets on each side should match the number of dimensions the object has. Hence, if it’s just a vector of data (like an array that is part of a series), you can use [ : ], but if it’ more like a matrix (2-D), then you need double squared brackets [[ : ]]. 
 
Best,
365 Vik

Thank you for your answer. But I have used the same command used in the tutorial for the same scenario. Command used in tutorial : reason_columns.loc[:, 1:14]. Command I used: reason_column.loc[:, 1:14] where reason_column and reason_columns both are dummy variables (2-D matrix).

6 months