在Pandas DataFrame中找到第一个和最后一个非NaN值

编程入门 行业动态 更新时间:2024-10-25 10:34:03
本文介绍了在Pandas DataFrame中找到第一个和最后一个非NaN值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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值

本文发布于:2023-10-24 08:35:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   中找到   Pandas   DataFrame   NaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!