How to compute the absolute value with Pandas using Python

1 min

Pandas bring a lot to the table when you are dealing with mathematical operations.

Here is a simple example of how to compute the absolute value of a column.

# We import our pandas as library
import pandas as pd

# We create a sample dataframe
df = pd.DataFrame({"col1" : [-13, 21, -2, 10]})

# We compute the absolute value of a column
print(df["col1"].abs())
How to compute the absolute value with Pandas using Python

Here you are! You now know how to compute the absolute value with Pandas using Python.

More on DataFrames

If you want to know more about DataFrame and Pandas. Check out the other articles I wrote on the topic, just here :

Pandas - The Python You Need
We gathered the only Python essentials that you will probably ever need.