python - Filtering rows by `df.str.split` on columns in pandas -
i have dataframe looks following
url1, labela:0.5 url2, labelb:0.4 url3, labelc:0.7
i trying following, split label column ':' , filter numeric value, greater 0.6. in above case, filter out rows url1 , url2 since values 0.5 , 0.4, respectively.
i did following won't work:
df = df[df["labels"].str.split(':').get(1).astype('float') >= 0.6]
i guess happen get(1)
give me second row instead of imaginary second column after split. tried bunch of variation of didn't work. hope illustrate idea though. elegant way this?
thanks.
you can use df.str.split(..., expand=true)
followed type conversion float df.astype
, boolean indexing
:
in [782]: df[df['labels'].str.split(':', expand=true)[1].astype(float) >= 0.6] out[782]: url labels 2 url3 labelc:0.7
Comments
Post a Comment