Select row using the length of list in pandas cell

柔情痞子 提交于 2020-01-07 05:38:29

问题


I have a table df

    a   b    c
1   x   y   [x]

2   x   z   [c,d]

3   x   t   [e,f,g]

Just wondering how to select the row using the length of c column

such as

df.loc[len(df.c) >1]

I know this is not right.... what should be the right one?


回答1:


You can using

df.loc[np.array(list(map(len,df.c.values)))>1]



回答2:


Try this:

df[df.c.map(len)>1]


来源:https://stackoverflow.com/questions/47720421/select-row-using-the-length-of-list-in-pandas-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!