Created
July 13, 2019 13:34
-
-
Save gary136/4802476dd0d999a87af3e5cba9b2e37e to your computer and use it in GitHub Desktop.
sales_aggregate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sales_aggregate(Id): | |
y_m = y_m_generator(2010, 2018) | |
dfs = [] | |
for y,m in y_m: | |
p = str(y)+'0'+str(m) if m<10 else str(y)+str(m) | |
(mapping_y, mapping_m) = (y, m+1) if m!=12 else (y+1, 1) | |
df = pd.read_sql_query('select * from SII_REV_{} where ID = "{}"'.format(p, Id), con=engine) | |
df['Y_M'] = p | |
df['Sales_Public_Date'] = datetime.datetime(mapping_y,mapping_m,7,0,0,0) | |
cols = df.columns.tolist() | |
cols = cols[-2:] + cols[:-2] | |
df = df[cols] | |
df['Sales_Date'] = datetime.datetime(y,m,1,0,0,0) | |
dfs.append(df) | |
df = pd.concat(dfs) | |
df.set_index('Sales_Date', inplace=True) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment