Series.ge() function compares two series element-wise, and returns
True if the series
a is greater than or equal to series
False is returned.
Series.ge(other, level=None, fill_value=None, axis=0)
other: This represents the other series to be compared.
level (optional): The default value is
None. It represents the level to be broadcasted (in the case of multilevel).
fill_value: This represents the value to replace the missing values in the series. If the element in both corresponding series indexes is NaN, the result of filling at that specific index will be
None. The default value is
axis: This indicates the axis to perform the operation on. Value
0 indicates rows and
1 indicates columns. The default is 0.
The following code will demonstrate how to use the
Series.ge() function in pandas:
import pandas as pd import numpy as np # create Series a = pd.Series([17, np.nan, 9, np.nan, 23, 7, np.nan]) b = pd.Series([np.nan, 10, 28, 15, 23, 40, np.nan]) # value to fill nan replace_nan = 1 # finds greater or equal element between the two Series # using Series.ge() print(a.ge(b, fill_value=replace_nan))
In the code above:
Line 1–2: We import the pandas and NumPy libraries.
Lines 5–7: We create two series,
Lines 10: Then, we create a variable,
replace_nan, and assign a value to it. This replaces the NaN values in the series.
Line 13: We find the greater or equal to element in Series
b using the
Note: If the element in both corresponding series indexes is NaN, the default value for
fill_valuewill be used.
View all Courses