我有一个Pandas DataFrame 按日期索引。有许多列,但是很多列只是部分时间序列的填充。我想找到第一个和最后一个值 - NaN 值的位置,以便我可以提取日期,并查看特定列的时间序列的时间长度
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 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的解决方案完美地返回第一个和最后一个非 NaN值使用 Series.first_valid_index 和 Series.last_valid_index 。
@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.
更多推荐
在Pandas DataFrame中找到第一个和最后一个非NaN值
发布评论