Python | Pandas Series.abs()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Series.abs() method is used to get the absolute numeric value of each element in Series/DataFrame.
Syntax: Series.abs()
Parameters: No parameters
Returns: Return the Series or DataFrame containing the absolute value of each element.
Code #1:
# importing pandas module import pandas as pd # creating lists lst = [2, -10.87, -3.14, 0.12] lst2 = [-10.87 + 4j] ser = pd.Series(lst) ser1 = pd.Series(lst2) # printing values explaining abs() print(ser1.abs(), '\n\n', ser.abs()) |
Output:
0 11.582612 dtype: float64 0 2.00 1 10.87 2 3.14 3 0.12 dtype: float64
Code #2: Explaning use of abs() on specific row
# importing pandas module import pandas as pd df = pd.DataFrame({'Name': ['John', 'Hari', 'Peter', 'Loani'], 'Age': [31, 29, 57, 40], 'val': [98, 48, -80, -14]}) df['ope'] = (df.val - 87).abs() df |
Output:
Name Age val ope 0 John 31 98 11 1 Hari 29 48 39 2 Peter 57 -80 167 3 Loani 40 -14 101
Recommended Posts:
- Python | pandas.map()
- Python | Pandas Series.dt.second
- Python | Pandas.to_datetime()
- Python | Pandas.melt()
- Python | Pandas Series.all()
- Python | Pandas Timestamp.tz
- Python | Pandas Timestamp.dst
- Python | Pandas.pivot()
- Python | Pandas Series.dt.day
- Python | Pandas Index.contains()
- Python | Pandas Series.str.pad()
- Python | Pandas Panel.mod()
- Python | Pandas.pivot_table()
- Python | Pandas dataframe.add()
- Python | Pandas Timestamp.now
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



