2
$\begingroup$

Is there a good toolbox for handling and analyzing missing values in Python 2.7?

There is a good toolbox for doing this in Python 3.6 here (missingno): https://github.com/ResidentMario/missingno

I need to work in Python 2.7. so, this is why I ask.

$\endgroup$
  • $\begingroup$ Pandas and SFrame. $\endgroup$ – Vaalizaadeh Jun 16 '18 at 12:07
1
$\begingroup$

First of all, visualize the missing values :

I am using Python 2.7

import pandas
import numpy
from pandas import DataFrame
import seaborn as sns

df = DataFrame({'A' : [0,1,numpy.nan, 5 ,6],'B':[30,numpy.nan,numpy.nan,8,10]})
df

     A  B
0   0.0 30.0
1   1.0 NaN
2   NaN NaN
3   5.0 8.0
4   6.0 10.0
sns.heatmap(df.isnull(),yticklabels=False,cbar=False,cmap='BuPu')

If u wanna drop rows containing missing values,

df.dropna(axis=0)

        A   B
    0   0.0 30.0
    3   5.0 8.0
    4   6.0 10.0

If u wanna drop columns containing missing values,

df.dropna(axis=1)

If you wanna fill NaN with a value:

df.fillna(0)


  A B
0   0.0 30.0
1   1.0 0.0
2   0.0 0.0
3   5.0 8.0
4   6.0 10.0

You can do a ffill/pad, bfill/backfill. Hit shit tab and expand the documentation if you are using jupyter.

For more info refer : https://pandas.pydata.org/pandas-docs/stable/missing_data.html

I hope this answers your question.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.