使用 pandas 连接不同长度的TimeSeries [英] concatenating TimeSeries of different lengths using Pandas

查看:213
本文介绍了使用 pandas 连接不同长度的TimeSeries的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中使用 pandas 。我有几个系列按日期索引,我想连接到一个DataFrame,但系列的长度不同,因为缺少日期等。我想要匹配的日期匹配,但是缺少数据的地方因为它被插入或只是使用以前的日期或类似的东西。那么最简单的方法是什么?

I am using pandas in python. I have several Series indexed by dates that I would like to concat into a single DataFrame, but the Series are of different lengths because of missing dates etc. I would like the dates that do match up to match up, but where there is missing data for it to be interpolated or just use the previous date or something like that. What is the easiest way to do this?

推荐答案

如果系列是在一个dict code>,您只需要执行以下操作:

If the Series are in a dict data, you need only do:

frame = DataFrame(data)

这将东西放入DataFrame和工会的所有日期。如果要向前填充值,可以调用 frame = frame.fillna(method ='ffill')

That puts things into a DataFrame and unions all the dates. If you want to fill values forward, you can call frame = frame.fillna(method='ffill').

这篇关于使用 pandas 连接不同长度的TimeSeries的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆