I have hourly data as shown. I want to convert hours to date. How can I do it?

- 9,425
- 7
- 41
- 65

- 11
- 1
- 2
-
Is "time" your hours? Also, since when do you start counting, if I get it right, you count hours, but when is your start point? – 1Mangomaster1 Feb 10 '20 at 10:39
-
Have you checked [this question](https://stackoverflow.com/questions/16176996/keep-only-date-part-when-using-pandas-to-datetime) and its answers? – itroulli Feb 10 '20 at 10:46
-
1`df['time']=pd.to_datetime(df['time'],format='%Y%m%d:%H%M')` – luigigi Feb 10 '20 at 10:50
2 Answers
I was also looking for the same solution. Below code might help
After resampling the data looks as below. In the code I am doing cumulative 6 hours sum up.
df.resample('6H', on = 'Hour').sum()

- 189
- 1
- 2
- 10
I didn't quite understand the question as a simple matter to count a date you need a start point to start counting. I can say there has been 24 since I started counting what date is it but if I won't say when I started counting nobody can know what date is it.
But assuming you have a start point it becomes simple, take the hours for each start point and divide by 24, you'll get the days and leftover hours, and then add them to your start date and this way you'll get date and time.
I am sorry if I did not understand you correctly, but this is the best I've realized from your question. Hope it helps :)
Example: Start Point: 10/02/2020, Time: 00:00AM Hours: 354 hours End Point: 10/02/2020 + 354 hours = 10/02/2020 + 14 days + 18 hours = (24/02/2020, 6:00PM)

- 346
- 1
- 6
- 16