My data files infrequently contain malformed lines (think abrupt power loss). When badness occurs across a timestamp, making it uninterpretable, the resulting DataFrame.Index
contains Not-a-Time (NaT
) values (because I've coerced it to).
My real problem is that instances of NaT
prevent the use of resample
. I need to remove them, first. Unfortunately, I haven't figured out if/how to use dropna
on the index itself. It's looking more and more like I need to make the index a column, operate on it, then re-make it the index. (But I don't want to do that.)
Is there an established idiom for dropping dataframe rows where the Index
values are null?
Drop all rows having at least one null value When it comes to dropping null values in pandas DataFrames, pandas. DataFrame. dropna() method is your friend.
To drop all the rows which contain only missing values, pass the value 0 to the axis parameter and set the value how='all' .
Use
df.loc[pd.notnull(df.index)]
for newer versions you can do
df.loc[df.index.notnull()]
or
df.loc[df.index.dropna()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With