Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- 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]]
- 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']
- df = pd.DataFrame(data,columns=Months)
- X = np.array([])
- Y = np.array([])
- for month in Months:
- loc = df.columns.get_loc(month)
- print(month,loc)
- if loc + 11 <= df.shape[1]:
- X = np.append(X,df.iloc[:,loc:loc+5].values,axis=0)
- Y = np.append(Y,df.iloc[:,loc+6:loc+1].values,axis=0)
- ### RESULTS EXPECTED ####
- X = [[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]
- 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