Pandas-How to use conditional statements correctly

Preface

This article is the 36th article of this column. I will continue to share the practical knowledge of python data analysis in the future, so remember to pay attention.

In python language, if statements are generally used for conditional judgment. So, what statement is used for conditional judgment in pandas? The method used to make judgments in pandas is the where function . The biggest difference between python's if statement and pandas' where function is that "the where function is a vector calculation, which is very fast and efficient and does not require the use of loops like the if statement in python." ".

The vector calculation of the where function is similar to that in an excel table. Using cell formulas can automatically apply to the entire column or row. So, how to use the where function of pandas, and what should we pay attention to during use? Follow the author and read the text below for detailed introduction. (complete code attached)

text

The where function in pandas can be said to be very powerful. Conditional judgment, numerical filtering, numerical substitution, etc. can be solved easily and quickly. As for its specific usage and implementation ideas, please refer to the text for details.

1. Precautions when using where function

In the process of using the where function

Guess you like

Origin blog.csdn.net/Leexin_love_Ling/article/details/132439486