0

I have date step like below

710040,  710784,  711456,  712200,  712920,  713664,
714384,  715128,  715872,  716592,  717336,  718056,
718800,  719544,  720216,  720960,  721680,  722424

This is a monthly dataset so date steps are month of different year. First one is Jan,1970 I want to convert it into month/year format.

ppwater
  • 2,315
  • 4
  • 15
  • 29
avi
  • 85
  • 8

1 Answers1

0

Do these numbers correspond to sequential months? If so you can create a mapping using a dictionary.

Here I am using datetime(year, month, day).strftime(format) to get "Jan, 1970" type strings.

>>> from datetime import datetime
>>> l = [710040,  710784,  711456,  712200,  712920,  713664,
... 714384,  715128,  715872,  716592,  717336,  718056,
... 718800,  719544,  720216,  720960,  721680,  722424]
>>> mapping = {
...     num : datetime(1970 + i // 12, i%12 + 1, 1).strftime('%b, %Y')
...     for i, num in enumerate(l)
... }

which gives

>>> mapping
{710040: 'Jan, 1970', 710784: 'Feb, 1970', 711456: 'Mar, 1970', 712200: 'Apr, 1970', 712920: 'May, 1970', 713664: 'Jun, 1970', 714384: 'Jul, 1970', 715128: 'Aug, 1970', 715872: 'Sep, 1970', 716592: 'Oct, 1970', 717336: 'Nov, 1970', 718056: 'Dec, 1970', 718800: 'Jan, 1971', 719544: 'Feb, 1971', 720216: 'Mar, 1971', 720960: 'Apr, 1971', 721680: 'May, 1971', 722424: 'Jun, 1971'}
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54