Home > Net >  Filtering based on catagories (string) empty data frame - pandas
Filtering based on catagories (string) empty data frame - pandas

Time:09-16

I have dataframe like this;

    bins      A        C    D
1.0 -  2.0    1.32    0.5   7
4.0 -  5.0    4.044   0.5   20
5.0 -  6.0    5.86    0.5   29
5.0 -  6.0    8.06    0.5   30
6.0 -  7.0    6.76    0.5   34
8.0 -  9.0    11.96   0.5   44
11.0 -  12.0  12.00   0.2   24
11.0 -  12.0  12.00   0.2   24

I want to get rid of the all rows where bins are below 11.0 - 12.0

I tried

df_.loc[df['bins'] > '11.0 - 12.0']
  
df.query(bins > '11.0 - 12.0')

but none of this is working as dont get any value back

any help would be appreciated!

Thanks in advance

CodePudding user response:

Maybe try:

>>> x = df['bins'].str.split('\s -\s ', expand=True).astype(float)
>>> df[x[0].ge(11) & x[1].ge(12)]
          bins     A    C   D
6  11.0 - 12.0  12.0  0.2  24
7  11.0 - 12.0  12.0  0.2  24
>>> 

CodePudding user response:

You can try to locate the first row index of bins in that value, then .loc from that index onwards:

df.loc[df.index[df['bins'] == '11.0 - 12.0'][0]: ]

Result:

          bins     A    C   D
6  11.0 - 12.0  12.0  0.2  24
7  11.0 - 12.0  12.0  0.2  24
  • Related