How to apply a function can test whether an element in a list in data frame with python-pandas?

后端 未结 2 718
轮回少年
轮回少年 2021-01-21 18:52

For a data frame df, it has a column col contains list value:

 id    col
 1     [1, 10, 23]
 2     [2, 11, 19, 29]
 ..
         


        
2条回答
  •  醉话见心
    2021-01-21 19:09

    try read the "apply" function in pandas document.

    df['has_element'] = df['col'].apply(lambda x: element in x)
    

提交回复
热议问题