Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. data = [[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]]
  5. Months=['201401','201402','201403','201404','201405','201406','201407','201408','201409','201410','201411','201412','201501','201502','201503','201504','201505','201506','201507','201508','201509','201510','201511','201512']
  6. df = pd.DataFrame(data,columns=Months)
  7.  
  8. X = np.array([])
  9. Y = np.array([])
  10.  
  11. for month in Months:
  12. loc = df.columns.get_loc(month)
  13. print(month,loc)
  14. if loc + 11 <= df.shape[1]:
  15. X = np.append(X,df.iloc[:,loc:loc+5].values,axis=0)
  16. Y = np.append(Y,df.iloc[:,loc+6:loc+1].values,axis=0)
  17.  
  18. ### RESULTS EXPECTED ####
  19. X = [[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]
  20. Y = [[7,8,9,10,11,12],[8,9,10,11,12,13],[9,10,11,12,13,14]]
Add Comment
Please, Sign In to add comment