I have a Pandas DataFrame, df
, and it has a column called _text
. I want to remove all rows where applying sentence_count
to the value in _text
column is not 0.
How would I go about this?
Normally with Pandas, I do something like:
result_df = result_df[result_df['_text'] != '']
But now I'm not just using the value in result_df['_text
], I'm filtering based on the value calculated by a function...
Thoughts?
Thanks!
Use pandas. DataFrame. drop() method to delete/remove rows with condition(s).
Pandas provide data analysts a way to delete and filter data frame using dataframe. drop() method. We can use this method to drop such rows that do not satisfy the given conditions.
If the function takes the sentence as its sole argument,
result_df[result_df['_text'].apply(sentence_count) != 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With