Selecting rows of pandas DataFrame where column is not empty list

六月ゝ 毕业季﹏ 提交于 2019-12-01 18:00:01

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]

Or you can follow your own logic using length of the list to determine keep or not .

df[df.my_list.str.len().gt(0)]
Out[1707]: 
  letter    my_list
0      a  [0, 1, 2]
1      b     [1, 2]
4      e     [0, 1]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!