FAQ: Creating, Loading, and Selecting Data with Pandas - Select Rows

This community-built FAQ covers the “Select Rows” exercise from the lesson “Creating, Loading, and Selecting Data with Pandas”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Data Analysis with Pandas

FAQs on the exercise Select Rows

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

How come we dont count the column names as part of the index?

Example: March is in the 2nd index if we dont count them just like an array

Because the column names aren’t part of the acutal data. We’d forever be slicing the first row out of our data otherwise.

1 Like

what is the full meaning of iloc?

For exercise 9, how do I add up all the count of visits in March?

why df.iloc**( )** does not work, why does it have to be [. ]. would appreciate if someone could dive into the ‘grammar’ of operator [ ] (if you could please :slight_smile: )

another real quick question. I am doing a side project, there’s a column name ‘shape’, here’s my syntax:
df[df.shape == ‘triangle’]. system reports error because DataFrame actually has an attribute named shape. so how do I go around it?

Like most of the indexing tools in Python (lists, strings, dictionaries etc.) the subscript syntax [] is used for accessing elements which actually calls the __getitem__ dunder method. There are some mild benefits to using this in Pandas objects like the support of slice notation but I think it’s mainly to be consistent with normal Python. I don’t know that this is the reason but I think it might be.

If you have a column with a label that matches an attribute of the dataframe (inherited or otherwise) then you must use the ["label"] syntax to access that column. The use of the . dotted attribute lookup is just a convenience method implemented by Pandas, the [] is more robust. For a little more info- https://discuss.codecademy.com/t/faq-modifying-dataframes-review/373659/34

I always get the error

when I execute “df.iloc[2]” I always get the error " unexpected indent ( "…does anybody know why?

check the indentation of the line of code that the error message is mentioning. (in other words, the system is telling you you put too much space at the beginning of at least one of your lines of codes.)

thanks a lot, after deleting the spaces it worked

If a series can only accept one data type, how can the input of .iloc be a row with multiple data types?

I see that it lists the dtype as an object, is there some kind of conversion going on to ensure dtype continuity?