Indexing & Selecting & Filtering in Pandas

Hands-on how to do selecting, indexing, and filtering in Pandas.

Tirendaz AI
Artificial Intelligence in Plain English

--

Photo by Icons8 Team on Unsplash

First, let me import the libraries.

To index data, you can the square brackets. To show this, let’s create a series using the arrange method.

Let’s see the obj variable.

Working with Index in Series

Let’s print the value of c.

You can do the same thing by entering the index number in square brackets.

You can slice the data.

Selecting in Series

Let’s select the specific rows.

You can do the same thing by using the index number.

Filtering in Series

Let’s see the values less than 2.

You can slice the values.

You can assign a value to the sliced piece.

Selecting in DataFrame

To show how to index in DataFrame, let me create a DataFrame.

Let’s see the column named two.

You can select more than one column.

You can slice the rows.

Filtering in DataFrame

You can use the boolean expression for selection.

You can assign data to specific values.

Selecting with iloc and loc methods

You can use the iloc method to select a row using the row’s index.

You can select the specific columns of the row.

You can select specific columns of multiple rows.

Let’s take a look at the loc method. You need to use names for loc.

Let’s select the rows up to Paris and the column named four.

To show how to use the negative index, let me create a Series named toy_data.

Now, I’m going to use a negative index.

Please clap 👏 if you like this blog post. Also, don’t forget to follow us on our Tirendaz Academy YouTube 📺, Twitter 😎, Medium 📚, LinkedIn 👍

See you in the next post …

--

--