Python dealing with months and years in arrays
Question: newbie question,

I have three arrays, one with years, one with months and one with my data.

The years array has which year the data occurs in, but as the data is
collected monthly, I have a lot of repeat years, eg
`[1996,1997,...,1997,1998,...,1998,1999 etc]`

Then in the array I have `[01,02,...,11,12,01,02, etc]`

Is there anyway to amalgamate these two arrays into one, and then plot them vs
my data?

I have tried multiplying the second array by `1/12` and adding it to the first
array, but would prefer a more elegant solution. Any tips?

Thank you.


Answer: You could use `zip` to combine the years and months into `datetime.date`
objects:

    
    
    dates = [DT.date(y,m,1) for y, m in zip(years, months)]
    

To plot using [matplotlib](http://matplotlib.org/):

    
    
    import matplotlib.pyplot as plt
    import datetime as DT
    import numpy as np
    
    years = [1996]+[1997]*12+[1998]*12
    months =[12]+range(1,13)+range(1,13)
    
    dates = [DT.date(y,m,1) for y, m in zip(years, months)]
    values = np.random.random(len(dates))
    
    plt.plot(dates, values)
    plt.show()
    

![enter image description here](http://i.stack.imgur.com/1GpVE.png)

