The Capabilities of '.loc' Function in #pandas #python

preview_player
Показать описание
Script:-

Hey Codos!

Previously, we learned how to access elements with the loc function, but did you know it's also great for performing logical operations on pandas series? Let’s check it out!

First, define your series. Suppose we want values greater than 3. We can use .loc and define the condition within it. Just like that, you get your filtered series!

Another way to apply logic is by using predefined functions. For greater than, use .gt, and there are many others like this.

An important concept to know is complementing, which reverses the logic. In our example of values greater than 3, if we use the minus sign, we get a series with values less than 3.

Give these techniques a try in your next project!
Рекомендации по теме