python - Calculate Numeric Value inside a String within a Pandas Column -


i have pandas dataframe , can select column want @ with:

column_x = str(data_frame[4]) 

if print column_x, get:

0     af1000g=0.09 1     af1000g=0.00 2     af1000g=0.14 3     af1000g=0.02 4     af1000g=0.02 5     af1000g=0.00 6     af1000g=0.54 7     af1000g=0.01 8     af1000g=0.00 9     af1000g=0.04 10    af1000g=0.00 11    af1000g=0.03 12    af1000g=0.00 13    af1000g=0.02 14    af1000g=0.00 ... 

i want count how many rows contain values af1000g=0.05 or less there are. rows contain values af1000g=0.06 or greater.

less_than_0.05 = count number of rows af1000g=0.05 , less  greater_than_0.05 = count number of rows af1000g=0.06 , greater     

how can count these values column when value in column string contains string , numeric content?

thank you.

rodrigo

you can use apply extract numerical values, , counting there:

vals = column_x.apply(lambda x: float(x.split('=')[1])) print sum(vals <= 0.05) #number of rows af1000g=0.05 , less print sum(vals >= 0.06) #number of rows af1000g=0.06 , greater 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -