- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Pandas series has a method for calculating absolute values of series elements. That function can also be used for calculating the absolute values of a series with complex numbers.

The abs() method in the pandas series will return a new series, which is having calculated absolute values of a series with complex numbers.

The absolute value of a complex number is $\sqrt{a^{2}+b^{2}}$ whereas a is the real value and b is the imaginary value of a complex number.

# importing pandas packages import pandas as pd #creating a series with null data s_obj = pd.Series([2.5 + 3j, -1 - 3.5j, 9 - 6j, 3 + 2j, 10 + 4j, -4 + 1j]) print(s_obj, end='\n\n') #calculate absolute values result = s_obj.abs() #print the result print(result)

In the following example, we have created a series with complex numbers. After that, we have calculated absolute values for each complex number in series s_obj.

In our series, there are some positive complex numbers and negative complex numbers. We can see the absolute values for each complex in the output block below.

0 2.500000+3.000000j 1 -1.000000-3.500000j 2 9.000000-6.000000j 3 3.000000+2.000000j 4 10.000000+4.000000j 5 -4.000000+1.000000j dtype: complex128 0 3.905125 1 3.640055 2 10.816654 3 3.605551 4 10.770330 5 4.123106 dtype: float64

In this output block, we have both series objects, one series with complex numbers and another with corresponding absolute values of complex numbered series. By using the abs() method of the pandas series we have calculated the absolute values of each complex number in the series.

# importing pandas packages import pandas as pd #creating a series with null data s = pd.Series([-0.3 - 0.3j, 1.3 + 0.3j, 4.2 + 5.29j, -9.037-5.03j, 2.34+2.1j]) print(s, end='\n\n') #calculate absolute values result = s.abs() #print the result print(result)

This is another example of calculating the absolute value of a series with complex numbers. Initially, we have created a series object with complex numbers, then calculated the absolute values for those complex numbers.

0 -0.300000-0.300000j 1 1.300000+0.300000j 2 4.200000+5.290000j 3 -9.037000-5.030000j 4 2.340000+2.100000j dtype: complex128 0 0.424264 1 1.334166 2 6.754561 3 10.342547 4 3.144137 dtype: float64

In the above output block we can see the a series object with resultant absolute values of complex numbered series.

- Related Questions & Answers
- How to calculate the frequency of each item in a Pandas series?
- How to calculate absolute value in Python?
- How to get the index and values of series in Pandas?
- Selecting with complex criteria from a Pandas DataFrame
- How to change index values of a Pandas series after creation?
- How to sort a Pandas Series?
- How to Plot Complex Numbers in Python?
- How does modulus work with complex numbers in Python?
- Python - Calculate the mean of column values of a Pandas DataFrame
- Python - Calculate the median of column values of a Pandas DataFrame
- Python - Calculate the count of column values of a Pandas DataFrame
- Python - Calculate the maximum of column values of a Pandas DataFrame
- Python - Calculate the minimum of column values of a Pandas DataFrame
- How to replace NaN values by Zeroes in a column of a Pandas Series?
- Complex Numbers in C#

Advertisements