Greater Than Equal to comparison for the elements from two pandas Series using ge() function
The ge() function compares elements of one series with elements of another series to determine whether the first element is greater than the second. The same way a series can be compared with a Python sequence such as list, tuple and so on.
The function ge() compares elements from one Series with elements from another Series and determines whether the first element is greater than or equal to the second element. The results of the comaprisions are returned as a Series.
Calling the method ge() is equal to applying the >= operator . However, calling the function ge() allows a fill_value parameter to be specified for replacing the NaN/None values with default values.
In the same way elements of a pandas Series can be compared with any Python sequence such as list and tuple.
Example - Comparing elements from two series objects using ge()
python
# Python example program to compare pandas series objects
import pandas as pds
# Compare strings present in two pandas.series objects
series1 = pds.Series(["Hello", "World"]);
series2 = pds.Series(["Hello", "Universe"]);
comparisionResult = series1.ge(series2);
print("Result of comparing two pandas series objects with strings using ge():");
print(comparisionResult);
# Compare integers present in two pandas.series objects
series1 = pds.Series([2, 4, 6, 8 , None]);
series2 = pds.Series([1, 3, 6, 9, 10]);
print("Result of comparing two pandas series objects with integers using ge():");
comparisionResult = series1.ge(series2, fill_value=0);
print(comparisionResult);
Output
Output
Result of comparing two pandas series objects with strings using ge():
0 True
1 True
dtype: bool
Result of comparing two pandas series objects with integers using ge():
0 True
1 True
2 True
3 False
4 False
dtype: bool
Example – Comparing a pandas Series with a Python sequence using ge()
python
# Python example program to compare a pandas series
# with a Python sequence
import pandas as pds
s1 = pds.Series(["a", "b", "c", "d", "e"]);
s2 = ("c", "a", "d", "b", "e");
resultsSeries = s1.ge(s2);
print("Contents of the pandas series instance s1:");
print(s1);
print("Contents of the pandas series instance s2:");
print(s2);
print("Result of comparing the elements of a series with a Python sequence using ge():");
print(resultsSeries);
Output
Output
Contents of the pandas series instance s1:
0 a
1 b
2 c
3 d
4 e
dtype: object
Contents of the pandas series instance s2:
('c', 'a', 'd', 'b', 'e')
Result of comparing the elements of a series with a Python sequence using ge():
0 False
1 True
2 False
3 True
4 True
dtype: bool
Your privacy choices
We'd like to use Google Analytics cookies to count visits and see which tutorials are useful.
They are only set if you accept. We don't use advertising cookies and we don't sell your data.
You can change your choice any time from “Your privacy choices” at the bottom of every page.
Privacy Policy
Your privacy choices
Your browser sent a Global Privacy Control signal, so analytics is off unless you turn it on here.
Strictly necessary
Remembers this choice in your browser. No cookies, nothing sent to anyone.Always on