Pandas DataFrame abs() method with examples

Spread the love

The abs() method in pandas return a Series/DataFrame with absolute numeric value of each element. This function only applies to elements that are all numeric.

Examples –

Let’s create a dataframe with some positive and some negative values.

import pandas as pd

df = pd.DataFrame({'A':[5, 10, -6, -2, -9],
                  'B':[-6, -7, -15, 20, 15]})

Now, to convert all negative values to positive we can use the abs() method.


Rating: 1 out of 5.

Leave a Reply