我有一个这样的数据框:
test = pd.DataFrame(columns=['A','B'])
test.loc[0,'A'] = 'a'
test.loc[0,'B'] = []
test.loc[1,'A'] = 'b'
test.loc[1,'B'] = ['a','b']
我想获取另一个数据框,其中包含“B”列包含空列表时的行。这样做的 Pythonic 方式是什么?
A B
0 a []
非常感谢
最佳答案
由于空列表将被解释为以矢量化方式处理的集合,我看不到任何测试它的方法,只能深入到 apply
调用:
test.B.apply(lambda c: c==[])
Out[71]:
0 True
1 False
Name: B, dtype: bool
test[test.B.apply(lambda c: c==[])]
Out[72]:
A B
0 a []
关于python - 如何在 Python 的数据框列中获取包含空列表的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42143116/