python numpy中的日期数据插值
我有一个由两个列组成的.CSV,我将其导入为numpy数组。第一列是日期数据数据,每个月都有一块数据。第二列是该月的相应值。
我想插入数据,以便每天为每天创建新的Datatime行,并为每天的相应值创建。如果可能的话,我还想为插值值引入一些随机噪音,但我知道这是很多要问的。
这是一个数据示例:
Date,Value
01/06/2010 00:00,42.18
01/07/2010 00:00,43.53
01/08/2010 00:00,39.95
01/09/2010 00:00,41.12
01/10/2010 00:00,43.5
01/11/2010 00:00,46.4
01/12/2010 00:00,58.03
01/01/2011 00:00,48.43
01/02/2011 00:00,46.47
01/03/2011 00:00,51.41
01/04/2011 00:00,50.88
01/05/2011 00:00,50.27
01/06/2011 00:00,50.82
非常感谢您的帮助 - 我知道scipy.interpaly
,但不确定这是否可以适用于DateTime格式?
I have a .csv consisting of two columns, which I have imported as a numpy array. The first column is datetime data with one piece of data every month. The second column is the corresponding value for that month.
I want to interpolate the data so as to create new datatime rows for every day and also a corresponding value for each day too. If possible, I would also like to introduce some random noise for the interpolated values, but I know this is a lot to ask.
Here is a sample of the data:
Date,Value
01/06/2010 00:00,42.18
01/07/2010 00:00,43.53
01/08/2010 00:00,39.95
01/09/2010 00:00,41.12
01/10/2010 00:00,43.5
01/11/2010 00:00,46.4
01/12/2010 00:00,58.03
01/01/2011 00:00,48.43
01/02/2011 00:00,46.47
01/03/2011 00:00,51.41
01/04/2011 00:00,50.88
01/05/2011 00:00,50.27
01/06/2011 00:00,50.82
Thanks very much for your help - I know of scipy.interpolate
, but not sure if this can work with datetime format or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的
Date
列已排序并包含字符串(不是日期)值,并且您的Values
列包含浮点数,这是一种获取第一天之间每一天的插值的方法和最后一个日期,假设采用DD/MM/YYYY
格式:这非常麻烦,我确信有一种更有效的方法,但它达到了目的。如果您有任何疑问,请告诉我。
Assuming your
Date
column is sorted and contains string (not date) values and yourValues
column contains floats, this is a way to get the interpolated value for every day between the first and last date, assumingDD/MM/YYYY
format:It's very cumbersome and I'm sure there's a more efficient way, but it serves the purpose. Let me know if you have any questions.