Column Type from Str to int or float pandas

Question:

I am using group by function of pandas, instead of adding numbers, pandas think it is a string and return like: 3,000,000,000.0092,315,000.00 instead of 3,092,315,000. i have tried several methods of conversions but each time it returns "ValueError: could not convert string to float: ‘3,000,000,000.00’"
i am unable to attach csv file, that might be the real problem.

df['AMOUNT'] = df['AMOUNT'].astype('float')

enter image description here

Asked By: Ahmad

||

Answers:

Try to replace , with “ first.

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

Answered By: JayPeerachai
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.