简体   繁体   English

我希望能够重新采样我的时间序列数据以获得每日平均值

[英]I want to be able to resample my time series data for the daily mean

I want to be able to resample my time series data for the daily mean. 我希望能够重新采样我的时间序列数据的每日平均值。 I have code for this, however the file I want to resample (an output file from a model) has time(d) where the days are numbered 1 to infinity rather than a date. 我有代码,但是我要重新采样的文件(模型的输出文件)具有time(d),其中天数被编号为1到无穷大而不是日期。 Also, if rainfall occurred on a day, the output will have two values for that day with the second time(d) for that day having a fraction (eg. 1 and 1.00053). 同样,如果一天中出现降雨,则输出将具有该天的两个值,而该天的第二个时间(d)则有一个分数(例如1和1.00053)。 What I need is to convert these day-numbers into dates, starting at 01/01/1900. 我需要将这些天数转换为日期,从01/01/1900开始。 When there are two values for the same day (eg. 1 and 1.00053) - they need to have the same date as well. 当同一天有两个值(例如1和1.00053)时,它们也需要具有相同的日期。

Maybe next time you can describe your question more clear with code you have already tried. 也许下次您可以使用已经尝试的代码更清楚地描述您的问题。 Try this in Python. 在Python中尝试。

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import datetime

day = [1, 1.00053]

if __name__ == '__main__':


    day = map(round, day)

    srcDay = datetime.datetime.strptime('01/01/1990', '%d/%m/%Y')    
    result = []
    for i in day:
        delta = datetime.timedelta(days=i)
        result.append(srcDay+delta)

    # you can use any kind of format you like 
    print result[0].strftime('%d-%m-%Y')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM