8.5k 270+ dataframe ,
price_dic = {1: 10, 2: 11, 3: 12, 5: 15}
df = pd.DataFrame({'days': pd.Series(price_dic.keys(),index=range(len(price_dic))),'price': pd.Series(price_dic.values(),index=range(len(price_dic)))})
df['prod_name'] = "Knote"
df
Out[80]:
days price prod_name
0 1 10 Knote
1 2 11 Knote
2 3 12 Knote
3 5 15 Knote
df['Date'] = pd.to_datetime("Feb. 1, 2015") + pd.to_timedelta(df.days,'D')
df
Out[82]:
days price prod_name Date
0 1 10 Knote 2015-02-02
1 2 11 Knote 2015-02-03
2 3 12 Knote 2015-02-04
3 5 15 Knote 2015-02-06
Update:
Dataframe ,
, prod, - , ,
,
product_list = [1001,1002,1003]
y_dict = [{1: 10, 2: 11, 3: 12, 5: 15},
{1: 10, 3: 11, 6: 12, 8: 15},
{1: 90, 2: 100, 7: 120, 9: 100}]
start_dt_list = ['Feb 05 2015','Feb 01 2015','Feb 06 2015']
fdf = pd.DataFrame(columns =['P_ID','Date','Price','Days'])
Out[73]:
Empty DataFrame
Columns: [P_ID, Date, Price, Days]
Index: []
for pid,j ,st_dt in zip(product_list, y_dict,start_dt_list):
df = pd.DataFrame({'P_ID' : pd.Series([pid]*len(j)) ,
'Date' : pd.Series([pd.to_datetime(st_dt)]*len(j)),
'Price': pd.Series(j.values(),index=range(len(j))),
'Days': pd.Series(j.keys(),index=range(len(j)))
})
fdf = fdf.append(df,ignore_index=True)
fdf.head(2)
Out[75]:
Date Days P_ID Price
0 2015-02-05 1 1001 10
1 2015-02-05 2 1001 11
fdf['Date'] = fdf['Date'] + pd.to_timedelta(fdf.Days,'D')
fdf
Out[77]:
Date Days P_ID Price
0 2015-02-06 1 1001 10
1 2015-02-07 2 1001 11
2 2015-02-08 3 1001 12
3 2015-02-10 5 1001 15
4 2015-02-09 8 1002 15
5 2015-02-02 1 1002 10
6 2015-02-04 3 1002 11
7 2015-02-07 6 1002 12
8 2015-02-07 1 1003 90
9 2015-02-08 2 1003 100
10 2015-02-15 9 1003 100
11 2015-02-13 7 1003 120