Pandas Series all() Method
In this tutorial, we will learn the Python pandas Series.all()
method. This method can be used to check whether the elements in the Series are True
or False
. This method returns the True only if all the elements are True otherwise it returns False.
The below shows the syntax of the Series.all()
method.
Syntax
Series.all(axis=0, bool_only=None, skipna=True, level=None, **kwargs)
Example: Pandas Series.all()
method
Let's create a Series and check the elements using the Series.all()
method. In this example, we created three series with different elements, as you can see for the first series only we got True and for the remaining series, we got False. Because Series.all()
method returns False if the Series contains at least one element as False. See the below example.
#importing pandas as pd
import pandas as pd
#creating Series
s_1=pd.Series([True,True])
s_2=pd.Series([False,False])
s_3=pd.Series([True,False])
print(s_1.all())
print(s_2.all())
print(s_3.all())
True
False
False
Example 2: Pandas Series.all()
Method
In this example, we are checking the Series that consists of null values
, '0'
and '1'
as elements and also with the empty Series
. The Series.all()
method returns False
for the null values
and for number '0'
. See the below example.
#importing pandas as pd
import pandas as pd
import numpy as np
#creating Series
s_1=pd.Series([True,np.NaN,np.NaN])
s_2=pd.Series([])
s_3=pd.Series([1])
s_4=pd.Series([0])
print(s_1.all(skipna=False))
print(s_2.all())
print(s_3.all())
print(s_4.all())
nan
True
True
False
Example 3: Pandas Series.all()
Method
Here, in this example, we will check the two Series. The Series.all()
method returns True
only if the given condition matches otherwise it returns False
. See the below example.
#importing pandas as pd
import pandas as pd
#creating Series
s_1=pd.Series([1,2,3])
s_2=pd.Series([4,5,6])
print(all(s_1>s_2))
print(all(s_1<s_2))
False
True
Conclusion
In this tutorial, we learned how to the Series.all()
method of the python pandas. We solved examples by applying this method on DataFrame.