Search code examples
pythondatetime-seriesdate-formattingdate-math

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. 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). What I need is to convert these day-numbers into dates, starting at 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.


Solution

  • Maybe next time you can describe your question more clear with code you have already tried. Try this in 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')