Examples
import numpy as np
import pandas as pd
s = pd.Series([-2.10, 3, -4.44, 5])
s.abs()
Absolute numeric values in a Series with complex numbers:
s = pd.Series([2.2 + 1j])
s.abs()
Absolute numeric values in a Series with a Timedelta element:
s = pd.Series([pd.Timedelta('1 days')])
s.abs()
Select rows with data closest to certain value using argsort:
df = pd.DataFrame({
'p': [2, 3, 4, 5],
'q': [20, 30, 40, 50],
'r': [200, 50, -20, -40]
})
df
df.loc[(df.r - 42).abs().argsort()]