Change language

Python | Pandas Series.le ()

Pandas series.le() is used to compare each item in a Caller series against a skipped series. It returns True for every element that is less than or equal to an element in the passed series.

Note: results are returned based on series comparison of callers "= other series.

Syntax: Series.le (other, level = None, fill_value = None, axis = 0)

Parameters:
other: other series to be compared with
level: int or name of level in case of multi level
fill_value: Value to be replaced instead of NaN
axis: 0 or ’index’ to apply method by rows and 1 or ’columns’ to apply by columns.

Return type: Boolean series

Example # 1: NaN handling

In this example, two series are created using pd.Series () . The series contains several zero values ​​and several equal values ​​with the same indices. The series are compared using the le () method and 10 is passed to the fill_value parameter to replace the NaN values ​​with 10.

# pandas module import

import pandas as pd 

  
# numpy module import

import numpy as np 

 
# create episode 1

series1 = pd.Series ([ 11 , 0 , 2 , 43 , < code class = "value"> 9 , 27 , np.nan , 10 , np.nan]) 

 
# create series 2

series2 = pd.Series ([ 16 , np. nan, 2 , 23 , 5 , 40 , 54 , 3 , 19 ]) 

 
# Replacing NaN

repla ce_nan = 10

  
# call and return to the result variable

result = series1.le (series2, fill_value = replace_nan)

 
# display
result 

Output:
As shown in the output, True was returned wherever the value in the caller row was less than or equal to the value in the passed row. You can also see that the zero values ​​have been replaced with 10 and the comparison has been done using that value. 

Example # 2: Calling Series with str objects

In this example, two series are created using pd.Series () . The series also contains some string values. In the case of strings, the comparison is performed against their

# pandas module import

import pandas as pd 

 
# numpy module import

import numpy as np 

 
# create series 1

series1 = pd.Series ([ ’A’ , 0 , ’c’ , 43 , 9 , ’e’ , np.nan, ’x’ , np.nan]) 

 
# create episode 2

series2 = pd.Series ([ ’v ’ , np.nan, ’ c’ , 23 , 5 , ’D’ , 54 , ’p’ , 19 ]) 

 
# NaN replacement  

replace_nan = 10

 
# call and return to the result variable

result = series1.le (series2, fill_value = replace_nan)

 
# display
result 

Output:
As you can see from the output, in the case of strings, the comparison was performed using their ASCII values. 

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically