CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

abs() Method of DataFrame

< Back


Use:
Return a Series/DataFrame with an absolute numeric value of each element.

Prototype:
<DataFrame_Obj>.abs ( )

import pandas as pd

df = pd.DataFrame({
    'a': [4, 5, 6, 7],
    'b': [10, 20, 30, 40],
    'c': [100, 50, -30, -50]
})

print(df)

   a   b    c
0  4  10  100
1  5  20   50
2  6  30  -30
3  7  40  -50
The absolute functions abs() will return the positive values (i.e. absolute values). All the columns should be integer, Otherwise error will occour.

print(df.abs())

   a   b    c
0  4  10  100
1  5  20   50
2  6  30   30
3  7  40   50

No comments:

Post a Comment