0

I have time series data with other fields. Now I want create more columns like

 valueonsamehour1daybefore,valueonsamehour2daybefore,
 valueonsamehour3daybefore,valueonsamehour1weekbefore,
 valueonsamehour1monthbefore

If values are not present at the hour then value should be set as zero dataframe can be loaded from here

url = 'https://drive.google.com/file/d/1BXvJqKGLwG4hqWJvh9gPAHqCbCcCKkUT/view?usp=sharing'
path = 'https://drive.google.com/uc? export=download&id='+url.split('/')[-2]
df = pd.read_csv(path,index_col=0,delimiter=",")

The DataFrame looks like the following:

| time             | StartCity | District | Id | stype | EndCity | Count                                                          
2021-09-15 09:00:00          1       104  2713     21        9      2
2021-05-16 11:00:00          1       107  1044     11        6      1
2021-05-16 12:00:00          1       107  1044     11        6      0
2021-05-16 13:00:00          1       107  1044     11        6      0
2021-05-16 14:00:00          1       107  1044     11        6      0
2021-05-16 15:00:00          1       107  1044     11        6      0
2021-05-16 16:00:00          1       107  1044     11        6      0
2021-05-16 17:00:00          1       107  1044     11        6      0
2021-05-16 18:00:00          1       107  1044     11        6      0
2021-05-16 19:00:00          1       107  1044     11        6      0
2021-05-16 20:00:00          1       107  1044     11        6      0
2021-05-16 21:00:00          1       107  1044     11        6      0
2021-05-16 22:00:00          1       107  1044     11        6      0
2021-05-16 23:00:00          1       107  1044     11        6      0
2021-05-17 00:00:00          1       107  1044     11        6      0
2021-05-17 01:00:00          1       107  1044     11        6      0
2021-05-17 02:00:00          1       107  1044     11        6      0
2021-05-17 03:00:00          1       107  1044     11        6      0
2021-05-17 04:00:00          1       107  1044     11        6      0
2021-05-17 05:00:00          1       107  1044     11        6      0
2021-05-17 06:00:00          1       107  1044     11        6      0
2021-05-17 07:00:00          1       107  1044     11        6      0
2021-05-17 08:00:00          1       107  1044     11        6      0
2021-05-17 09:00:00          1       107  1044     11        6      0
2021-05-17 10:00:00          1       107  1044     11        6      0
2021-05-17 11:00:00          1       107  1044     11        6      0
Yannis P.
  • 2,745
  • 1
  • 24
  • 39
Houd
  • 1
  • 1
  • 1
    Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) as **text**, not images: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – mozway Jan 27 '22 at 15:06
  • Merge against your own data with the appropriate time offsets – ifly6 Jan 27 '22 at 15:43
  • Not able to understand, I know I can do it in loop but I don't want to that – Houd Jan 27 '22 at 16:06

0 Answers0