Indexing & Selecting & Filtering in Pandas
Hands-on how to do selecting, indexing, and filtering in Pandas.
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.
That’s it. I hope you enjoy it. You can find the notebook here.
If you haven’t read it, I strongly recommend you to read the following articles about Pandas. 👇👇👇
- Introduction to the Pandas
- Important Methods in Pandas
- Arithmetic Operations in Pandas
- Sorting and Ranking in Pandas
- Summarizing And Computing Descriptive Statistics in Pandas
- Reading and Writing Data in Pandas
- How to Fix Missing Data in Pandas
- Data Transformation in Pandas
- Hierarchical Indexing in Pandas
- Combining And Merging Datasets in Pandas
- Reshaping And Pivoting in Pandas
- Groupby in Pandas
- Working with Groupby in Pandas
- Pivot Tables in Pandas
- Categorical Data in Pandas
- Working With Text Data in Pandas
- Practical Data Analysis with Pandas
- Multiple Selecting-Filtering in Pandas
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 …