k and m to int in pandas

Solutions on MaxInterview for k and m to int in pandas by the best coders in the world

showing results for - "k and m to int in pandas"
Filippo
08 Apr 2016
1In [31]: df.Val = (df.Val.replace(r'[KM]+$', '', regex=True).astype(float) * \
2   ....:           df.Val.str.extract(r'[\d\.]+([KM]+)', expand=False)
3   ....:             .fillna(1)
4   ....:             .replace(['K','M'], [10**3, 10**6]).astype(int))
5
6In [32]: df
7Out[32]:
8         Date        Val
90  2016-09-23      100.0
101  2016-09-22  9600000.0
112  2016-09-21    54200.0
123  2016-09-20   115300.0
134  2016-09-19    18900.0
145  2016-09-16   176100.0
156  2016-09-15    31600.0
167  2016-09-14    10000.0
178  2016-09-13  3200000.0
18
similar questions
queries leading to this page
k and m to int in pandas