O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Slicing a DataFrame

Having discussed slicing a series, let's talk about slicing a DataFrame. The good news is that, in talking about series slicing, a lot of the hard work is already done. We introduced loc and iloc as series methods, but they are DataFrame methods as well. After all, you should be thinking of DataFrames as multiple series glued together as columns.

We now need to think about how what we learned for series translates to a two-dimensional setting. If we use bracket notation, it will work only for the columns of the DataFrame. We will need to use loc and iloc to subset rows of the DataFrame. In truth, these methods can accept two positional arguments. The first positional argument determines which rows to select, and the second ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required