Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

k and M to int in pandas

In [31]: df.Val = (df.Val.replace(r'[KM]+$', '', regex=True).astype(float) * 
   ....:           df.Val.str.extract(r'[d.]+([KM]+)', expand=False)
   ....:             .fillna(1)
   ....:             .replace(['K','M'], [10**3, 10**6]).astype(int))

In [32]: df
Out[32]:
         Date        Val
0  2016-09-23      100.0
1  2016-09-22  9600000.0
2  2016-09-21    54200.0
3  2016-09-20   115300.0
4  2016-09-19    18900.0
5  2016-09-16   176100.0
6  2016-09-15    31600.0
7  2016-09-14    10000.0
8  2016-09-13  3200000.0
Comment

PREVIOUS NEXT
Code Example
Python :: leetcode 206 python 
Python :: iris data pandas scatterplot 
Python :: Half String 
Python :: fouier transformation in python open cv 
Python :: tb to pb with python calculator 
Python :: how to remove no data times plotly 
Python :: pandas plot column titles vertical 
Python :: abrir notebooks jupyter administrador de archivos 
Python :: python filter function 
Python :: django validate_comma_separated_integer_list 
Python :: how to make a config txt file on python 
Python :: re mobile no validate python 
Python :: Python turtle (built in shape) image size 
Python :: crop image using opencv with height and width 
Python :: exit from python manage py createsuperuser 
Python :: Optimize images in python using pillow 
Python :: ternary operator using dictionary in Python 
Python :: create a distance matrix from a coordinate matrix in python 
Python :: how to get rid of an instance variable python 
Python :: sorted key len python 
Python :: tkl to pkr 
Python :: yesterday date in python 
Python :: django abstractuser fields 
Python :: re.split 
Python :: transpose of a matrix in python using loop 
Python :: python difference 
Python :: pygame buttons 
Python :: for range python 
Python :: how to access variable of one function in another function in python 
Python :: how to create template folder in django 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =