Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.2k points)

I have a Pandas DataFrame 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-NaN values are located so that I can extract 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.

1 Answer

0 votes
by (107k points)

You can return the first and last non-NaN values by using the Series.first_valid_index and Series.last_valid_index, respectively.

If you are interested in learning Pandas and want to become an expert in Python Programming, then check out this Python Course and upskill yourself.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...