Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.
Pandas Series.all() function return whether all elements are True, potentially over an axis. It returns True unless there at least one element within a series or along a Dataframe axis that is False or equivalent (e.g. zero or empty).
Syntax: Series.all(axis=0, bool_only=None, skipna=True, level=None, **kwargs)
Parameter :
axis : Indicate which axis or axes should be reduced.
bool_only : Include only boolean columns.
skipna : Exclude NA/null values.
level : If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar.
**kwargs : Additional keywords have no effect but might be accepted for compatibility with NumPy.Returns : scalar or Series
Example #1: Use Series.all() function to check if all the values in the given series object is True or non-zero.
# importing pandas as pd import pandas as pd # Creating the Series sr = pd.Series([34, 5, 13, 32, 4, 15]) # Create the Index index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp'] # set the index sr.index = index_ # Print the series print(sr) |
Output :
Coca Cola 34 Sprite 5 Coke 13 Fanta 32 Dew 4 ThumbsUp 15 dtype: int64
Now we will use Series.all() function to check if all the values in the given series object is True and non-zero.
# check if all value is True # or non-zero result = sr.all() # Print the result print(result) |
Output :
True
As we can see in the output, the Series.all() function has successfully returned the True indicating that all the values in the given series is True or non-zero.
Example #2 : Use Series.all() function to check if all the values in the given series object is True or non-zero.
# importing pandas as pd import pandas as pd # Creating the Series sr = pd.Series([51, 10, 24, 18, 1, 84, 12, 10, 5, 24, 0]) # Create the Index # apply yearly frequency index_ = pd.date_range('2010-10-09 08:45', periods = 11, freq ='Y') # set the index sr.index = index_ # Print the series print(sr) |
Output :
2010-12-31 08:45:00 51 2011-12-31 08:45:00 10 2012-12-31 08:45:00 24 2013-12-31 08:45:00 18 2014-12-31 08:45:00 1 2015-12-31 08:45:00 84 2016-12-31 08:45:00 12 2017-12-31 08:45:00 10 2018-12-31 08:45:00 5 2019-12-31 08:45:00 24 2020-12-31 08:45:00 0 Freq: A-DEC, dtype: int64
Now we will use Series.all() function to check if all the values in the given series object is True and non-zero.
# check if all value is True # or non-zero result = sr.all() # Print the result print(result) |
Output :
False
As we can see in the output, the Series.all() function has successfully returned the False indicating that all the values in the given series is not True or non-zero. One of the values is zero in this series object.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | pandas.to_markdown() in Pandas
- Add a Pandas series to another Pandas series
- Python | Pandas Index.insert()
- Python | Pandas DatetimeIndex.inferred_freq
- Python | Pandas PeriodIndex.start_time
- Python | Pandas PeriodIndex.week
- Python | Pandas Timestamp.second
- Python | Pandas Series.asobject
- Python | Pandas str.join() to join string/list elements with passed delimiter
- Python | Pandas DataFrame.reset_index()
- Python | Pandas dataframe.notna()
- Python | Pandas PeriodIndex.weekday
- Python | Pandas Series.dt.floor
- Python | Pandas Index.get_slice_bound()
- Python | Pandas Dataframe.duplicated()
- Python | Pandas dataframe.notnull()
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Use Pandas to Calculate Statistics in Python
- Python | Pandas Timestamp.date
- Python | Pandas Timestamp.ctime
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

