I have a pandas DataFrame, with one of its columns being column of lists. I want to extract rows that have a specific element in corresponding list. (For example, DF is dataframe and DF['a'] is Series of lists. Then I want to find rows where there is an X element in corresponding DF['a'] list). How can I do it?
            Asked
            
        
        
            Active
            
        
            Viewed 378 times
        
    -2
            
            
        - 
                    3please post a data sample to replicate, else we will just be guessing and you may not find a relevant answer. Check [how to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – anky Mar 03 '19 at 11:51
1 Answers
0
            
            
        Is this what you mean?
import pandas as pd
d = ({             
   'a' : ['X','Y','Z','X','Y','Z','X'],                                                                                                                                                 
    })
df = pd.DataFrame(data=d)
df = df[df.a == 'X']
print(df)
   a
0  X
3  X
6  X
 
    
    
        jonboy
        
- 415
- 4
- 14
- 45
