So this recipe is a short example on how to drop NA rows from pandas dataframe. Let's get started.
import pandas as pd import seaborn as sb
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays. Seaborn is just for importing dataset for now.
df = sb.load_dataset('tips') df.to_csv('tips.csv') df['tip'][2:7]=None print(df.head(10))
Here we have simply imported tips dataset from seaborn library. Now we have modified the dataset a bit to introduce 'None' values in out dataset. Finally, we have printed the first 10 rows of our dataset.
df = df[df['tip'].notna()] print(df.head(10))
Now we use notna function to find the rows that dont have 'None' value in tip column. Finally, we have printed down our modified dataframe.
Once we run the above code snippet, we will see:
Scroll down the ipython file to visualize our dataset.