Selecting rows of pandas DataFrame where column is not empty list

前端 未结 2 357
你的背包
你的背包 2021-01-18 00:10

I have a pandas DataFrame where one column contains lists and would like to select the rows where the lists are not empty.

Example data:

df = pd.Data         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 01:04

    Empty lists evaluate to False in a boolean context

    df[df.my_list.astype(bool)]
    
      letter    my_list
    0      a  [0, 1, 2]
    1      b     [1, 2]
    4      e     [0, 1]
    

提交回复
热议问题