drop datetimeindex where df shows nan
<p>I have a pandas dataframe with datetime index which has nan values on some rows. How do I remove the datetimeindex along with the nan rows? </p>

<pre><code>2016-10-06 13:15:00  2.923383  0.007970 -0.001883
2016-10-06 13:30:00  2.809612  0.007389  0.001466
2016-10-06 13:45:00  3.022803  0.028234 -0.005162
2016-10-06 14:00:00  3.005836  0.017393 -0.000727
2016-10-06 14:15:00  3.031413  0.002826 -0.001097
2016-10-06 14:30:00  3.107922  0.011489  0.001837
2016-10-06 14:45:00  3.090017 -0.015071  0.006606
2016-10-06 15:00:00  3.032213 -0.028361 -0.008619
2016-10-06 15:15:00  3.010773 -0.020547  0.008827
2016-10-06 15:30:00  2.948293 -0.002611  0.013339
2016-10-06 15:45:00  2.965507 -0.012090  0.004819
2016-10-06 16:00:00  2.939935  0.009255 -0.016812
2016-10-06 16:15:00       NaN       NaN       NaN
2016-10-06 16:30:00       NaN       NaN       NaN
2016-10-06 16:45:00       NaN       NaN       NaN
2016-10-06 17:00:00       NaN       NaN       NaN
2016-10-06 17:15:00       NaN       NaN       NaN
2016-10-06 17:30:00       NaN       NaN       NaN
2016-10-06 17:45:00       NaN       NaN       NaN
2016-10-06 18:00:00  2.790215 -0.006258 -0.006561
2016-10-06 18:15:00  2.760398 -0.019173 -0.005650
2016-10-06 18:30:00  2.806837 -0.004759  0.003778
2016-10-06 18:45:00  2.707243 -0.011007  0.000657
2016-10-06 19:00:00  2.690583 -0.011315  0.011752
2016-10-06 19:15:00  2.632939 -0.010978  0.018907
2016-10-06 19:30:00  2.665248 -0.009146  0.016380
2016-10-06 19:45:00  2.637122 -0.015417  0.021086
2016-10-06 20:00:00  2.688877 -0.004790  0.009998
2016-10-06 20:15:00  2.574410 -0.000862  0.014240
2016-10-06 20:30:00  2.641405  0.010043  0.010205
</code></pre>

<p>I tried: </p>

<pre><code>for row in range(len(df)):
        if df.iloc[row,:] is None:
                df.index.drop(row)
</code></pre>

<p>but what is returned is the above. </p>

<p>Note that <code>df.dropna()</code> is not what I'm looking for... I am dealing with missing time-series data interpolation done on plotly. I am looking to connect the missing data so I don't have gaps (caused by NaN) or interpolation (caused by missing data but datatimeindex is still there) on charts. I don't want to go into it further but apparently I've been told removing the NaN rows <em>and</em> datetimeindex where the NaN rows appear is a solution... </p>

<p>If you just want to find the indices where there is <em>no</em> NaN in a row, you can do this:</p>

<pre><code># get a single column of T/F values that 
# where at least one value in the row is null
msk = df.isnull().any(axis=1)

# now drop all of the index values where msk = True
new_index = df.index.drop(msk[msk == True].index)
</code></pre>

<p>However, <code>new_index</code> is just a list of the index values where no columns are NaN.  Doing this does not modify the DataFrame instance.</p>

<p>You can also interpolate the data yourself with <a href="http://pandas.pydata.org/pandas-docs/stable/missing_data.html#interpolation" rel="nofollow"><code>interpolate()</code>.</a></p>

<p>You will likely want to do something like the following:</p>

<pre><code>df.interpolate(method="time")
</code></pre>

python pandas dataframe