About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Saturday, April 20, 2019

Removing Null Value rows from Dataframe in Pandas

I have an excel sheet with below records









Here if you see second and fourth rows having null value, so our objective to remove these rows from process, lets see how we can do with panda package of python

import pandas as pd
import numpy as np

df1 = pd.read_csv(
"NullFilterExample.csv")

print('Original DF with NULL value in rows \n',df1 , '\n')

for col in df1.columns:
    df1=df1[df1[col].notnull()]

print('After removing rows with NULL Value \n',df1)

Output:

Original DF with NULL value in rows
    account_no  branch  city_code customer_name  amount
0        2112  3212.0      321.0       Sidhika   19000
1        2119     NaN      215.0      Prayansh   12000
2        2115  4321.0      212.0       Rishika   15000
3        2435  2312.0        NaN      Sagarika   13000

After removing rows with NULL Value
    account_no  branch  city_code customer_name  amount
0        2112  3212.0      321.0       Sidhika   19000
2        2115  4321.0      212.0       Rishika   15000


Data Science with…Python J

Post Reference: Vikram Aristocratic Elfin Share

No comments:

Post a Comment