- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the any() method do in the pandas series?
The any() is one of the pandas.Series method, which is used to verify if there is any non-zero value present in the given series object.
The pandas.Series method “any()” will return a boolean value as an output. It will return True if any value in the given series is non-zero. otherwise, it will return False for all zero values of the given series object.
Example 1
import pandas as pd # create a series s = pd.Series([False, False]) print(s) print("Output: ") print(s.any())
Explanation
Let’s see an example, here we have created a pandas series object with all zero-values (nothing but False). And applied the any() method to the series object “s”.
Output
0 False 1 False dtype: bool Output: False
In the above block, we can see a series with Boolean values, all are False, which is nothing but zero-values. We have seen the boolean value “False” as an output for any() method, which is due to there being no single non-zero value present in the given series object.
Example 2
import pandas as pd # create a series s = pd.Series([False, True]) print(s) print("Output: ") print(s.any())
Explanation
Let’s take another example by creating it with a non-zero value in it, here we have created a pandas series object with a zero value (False) and non-zero value (True). And then applied the any() method to the series object “s”.
Output
0 False 1 True dtype: bool Output: True
The output of the any() method for this following example is “True” (can be seen in the above output block) which due to there is a non-zero value present in the given series object.
- Related Articles
- What does count method do in the pandas series?
- What does the all() method do in pandas series?
- What does the add() method do in the pandas series?
- What does the align() method do in the pandas series?
- What does the apply() method do in the pandas series?
- What does agg() method do in pandas series?
- What does the pandas series.filter() method do?
- How does the pandas Series idxmax() method work?
- How does the pandas Series idxmin() method work?
- What does axes in the pandas series mean?
- How does pandas series astype() method work?
- How does pandas series combine() method work?
- How does pandas series combine_first() method work?
- How does pandas series div() method work?
- What does series mean in pandas?
