Pandas DataFrame min() method with examples

Spread the love

The min() method in pandas find the minimum value of the columns or the rows. When the axis is set to axis=0 or index, It finds the minimum value for each columns and when the axis is set to axis=1 or columns, it finds the minimum value for each rows in the dataframe.

Example –

Let’s create a Dataset to work with.

import pandas as pd

data = {'Apple':[89, 89, 90, 110, 125, 84, 131, 123, 123, 140, 145, 145],
       'Orange': [46, 46, 50, 65, 63, 48, 110, 120, 60, 42, 47, 62],
       'Banana': [26, 30, 30, 25, 38, 22, 22, 36, 20, 27, 23, 34 ],
       'Mango': [80, 80, 90, 125, 130, 150, 140, 140, 135, 135, 80, 90]}

index = ['Jan','Feb','Mar','Apr','May','June','Jul','Aug','Sep','Oct','Nov','Dec']
df = pd.DataFrame(data, index=index)
df

1 . Find the minimum value for each columns –

By default min() method finds the minimum value for each columns. By default the axis is set to axis=0 or index.

df.min()

2 . Find the minimum value for each rows –

To find the minimum value for each rows we need to set the axis to axis=1 or columns.

df.min(axis=1)

Related Posts –

  1. Pandas DataFrame max() method with examples

Rating: 1 out of 5.

Leave a Reply