Python | Pandas Series.mode ()

Python Methods and Functions

Series.mode() Pandas Series.mode() returns the underlying data mode in the given Series object ... This function always returns Series, even if only one value is returned.

Syntax: Series.mode (dropna = True)

Parameter:
dropna: Don't consider counts of NaN / NaT

Returns: modes: Series

Example # 1: Use Series.mode () to find the mode of this series object.

# import pandas as pd

import pandas as pd

 
# Create a series

sr = pd.Series ([ 10 , 25 , 3 , 25 , 24 , 6 ])

 
# Create Index

index_ = [ 'Coca Cola' , 'Sprite' , ' Coke' , 'Fanta' , 'Dew' , ' ThumbsUp' ]

  
# set index

sr.index = index_

 
# Print series

print (sr)

Output:

We will now use Series.mode () to find the mode of this series object.

# return mode

result = sr. mode ()

 
# Print result

print (result)

Output:

As we can see in the output, Series.mode () successfully returned the mode of this series object.

Example # 2: Use Series.mode () to find the mode of a given series object. This series object contains some missing values.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ 19.5 , 16.8 , None , 22.78 , 16.8 , 20.124 , None , 18.1002 , 19.5 ])

 
# Print series

print (sr)

Output:

We will now use Series.mode () to find the mode of a given series object.

# return mode

result = sr.mode ()

 
# Print result

print (result)

Exit d:

As we can see in the output, Series.mode () successfully returned the mode of the given batch object.





Tutorials