I have a csv file. I read it:
import pandas as pd
data = pd.read_csv('my_data.csv', sep=',')
data.head()
It has output like:
id city department sms category
01 khi revenue NaN 0
02 lhr revenue good 1
03 lhr revenue NaN 0
I want to remove all the rows where sms
column is empty/NaN. What is efficient way to do it?
You can use the method
dropna
for this:See the documentation for more details on the parameters.
Of course there are multiple ways to do this, and there are some slight performance differences. Unless performance is critical, I would prefer the use of
dropna()
as it is the most expressive.Use
dropna
with parametersubset
for specify column for checkNaN
s:Another solution with
boolean indexing
andnotnull
:Alternative with
query
:Timings