Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter data frame using condition

Tags:

python

pandas

i have created a data frame like this:

d = {"one":[1,2,3],"two":[[["c",3],["a",4]],["b",5],["a",6]]}
pd.DataFrame(d)

My question is: how do i filter out a new data frame that column "two" contains only "a"

Expected result

like image 334
Huy Nguyen Bui Avatar asked Dec 06 '25 20:12

Huy Nguyen Bui


1 Answers

This should do it for you :

df.loc[df["two"].astype(str).str.contains("a")] 
like image 122
elPastor Avatar answered Dec 08 '25 10:12

elPastor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!