Bprodz Bprodz - 2 months ago 22
Python Question

Locate first and last non NaN values in a Pandas DataFrame

I have a Pandas

indexed by date. There a number of columns but many columns are only populated for part of the time series. I'd like to find where the first and last values non-
values are located so that I can extracts the dates and see how long the time series is for a particular column.

Could somebody point me in the right direction as to how I could go about doing something like this? Thanks in advance.


@behzad.nouri's solution worked perfectly to return the first and last non-NaN values using Series.first_valid_index and Series.last_valid_index, respectively.