1# convert all columns of DataFrame
2df = df.apply(pd.to_numeric) # convert all columns of DataFrame
3
4# convert just columns "a" and "b"
5df[["a", "b"]] = df[["a", "b"]].apply(pd.to_numeric)
1df_raw['PricePerSeat_Outdoor'] = pd.to_numeric(df_raw['PricePerSeat_Outdoor'], errors='coerce')
1In [39]:
2
3df['2nd'] = df['2nd'].str.replace(',','').astype(int)
4df['CTR'] = df['CTR'].str.replace('%','').astype(np.float64)
5df.dtypes
6Out[39]:
7Date object
8WD int64
9Manpower float64
102nd int32
11CTR float64
122ndU float64
13T1 int64
14T2 int64
15T3 int64
16T4 object
17dtype: object
18In [40]:
19
20df.head()
21Out[40]:
22 Date WD Manpower 2nd CTR 2ndU T1 T2 T3 T4
230 2013/4/6 6 NaN 2645 5.27 0.29 407 533 454 368
241 2013/4/7 7 NaN 2118 5.89 0.31 257 659 583 369
252 2013/4/13 6 NaN 2470 5.38 0.29 354 531 473 383
263 2013/4/14 7 NaN 2033 6.77 0.37 396 748 681 458
274 2013/4/20 6 NaN 2690 5.38 0.29 361 528 541 381
28