Py4D
Py4D

Reputation: 33

How to remove the decimal point in a Pandas DataFrame

What is the best way for removing decimals in a pandas dataframe?

Example Data:

1.10
2.20
3.30
4.40

Expected result:

110
220
330
440

Upvotes: 2

Views: 6937

Answers (3)

Herc01
Herc01

Reputation: 632

As far I am aware pandas always give you numbers on that format. Well if you are just want to change it for look or preference purposes then. Here is something for you suppose you already the name of that column is amount;

 df['amount']= (df['amount']).astype(str).str.replace('.', '')

Please note that the type of that column has been changed to string you can now retransform it into int.

Upvotes: 1

niraj
niraj

Reputation: 18208

You can try using as df['col'] = (df['col']*100).astype(int) as below:

df = pd.DataFrame({'col': [1.10, 2.20, 3.30, 4.40]})
df['col'] = (df['col']*100).astype(int)
print(df)

Output:

   col
0  110
1  220
2  330
3  440

Upvotes: 4

Capn Jack
Capn Jack

Reputation: 1241

If - as your comment suggests - the data just all needs to be multiplied by 100...

df['columnName'] = df['columnName'].apply(lambda x: x*100)

Upvotes: 1

Related Questions