Keiku
1/31/2017 - 10:19 AM

Convert number strings with commas in pandas DataFrame to float.

Convert number strings with commas in pandas DataFrame to float.

import pandas as pd
import locale
from locale import atof

df = pd.DataFrame([['1,200', '4,200'], ['7,000', '-0.03'], ['5', '0']])
#        0      1
# 0  1,200  4,200
# 1  7,000  -0.03
# 2      5      0
locale.setlocale(locale.LC_NUMERIC, '')
df.applymap(atof)
#         0        1
# 0  1200.0  4200.00
# 1  7000.0    -0.03
# 2     5.0     0.00