Pandas:基于应用函数删除行

时间:2017-07-25 22:50:31

标签: python pandas

我有一个Pandas DataFrame df,它有一个名为_text的列。我想删除将sentence_count应用于_text列中的值不为0的所有行。

我该怎么做?

通常使用Pandas,我会做类似的事情:

result_df = result_df[result_df['_text'] != '']

但现在我不只是使用result_df['_text]中的值,我根据函数计算的值进行过滤...

思想?

谢谢!

1 个答案:

答案 0 :(得分:2)

如果函数将句子作为唯一参数,

result_df[result_df['_text'].apply(sentence_count) != 0]