df["Q28aa_1_1"]
30 2,330,000
31 2900000
32 2,550,000
33 2570000
34 2850000
35 1,000,000
36 2200000
37 2900000
Above is an example of dataframe column I have.
df["Q28aa_1_1"]
30 2,330,000
31 2900000
32 2,550,000
33 2570000
34 2850000
35 1,000,000
36 2200000
37 2900000
Above is an example of dataframe column I have.
You should be able to replace commas and apply float by doing something like this.
import pandas as pd
df = pd.DataFrame()
df["Q28aa_1_1"] = ["2,330,000", " 2900000", "2,550,000", " 2570000", " 2850000", "1,000,000", " 2200000", " 2900000"]
df["Q28aa_1_2"] = ["2,330,000", " 2900000", "2,550,000", " 2570000", " 2850000", "1,000,000", " 2200000", " 2900000"]
df["Q28aa_1_3"] = ["2,330,000", " 2900000", "2,550,000", " 2570000", " 2850000", "1,000,000", " 2200000", " 2900000"]
for column in ["Q28aa_1_1","Q28aa_1_2", "Q28aa_1_3"]:
df[column] = df[column].str.replace(',','').apply(float)
output of df.head()
Q28aa_1_1 Q28aa_1_2 Q28aa_1_3
0 2330000.0 2330000.0 2330000.0
1 2900000.0 2900000.0 2900000.0
2 2550000.0 2550000.0 2550000.0
3 2570000.0 2570000.0 2570000.0
4 2850000.0 2850000.0 2850000.0