Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas - Turning column of mixed positive / negative numbers to positive [duplicate]

Tags:

python

pandas

In my dataframe I have a column containing numbers, some positive, some negative. Example

    Amount
0  -500
1   659
3   -10
4   344

I want to turn all numbers Df['Amount'] into positive numbers. I thought about multiplying all numbers with *-1. But though this turns negative numbers positive, and also does the reverse.

Is there a better way to do this?

like image 853
Jasper Avatar asked Jan 01 '18 20:01

Jasper


1 Answers

You can assign the result back to the original column:

df['Amount'] = df['Amount'].abs()

Or you can create a new column, instead:

df['AbsAmount'] = df['Amount'].abs()
like image 140
Tom Lynch Avatar answered Oct 22 '22 10:10

Tom Lynch