我有一张临时表resample('MS')
df['Start Date'] = pd.to_datetime(df['Start Date'])
df['End Date'] = pd.to_datetime(df['End Date'])
d1 = pd.melt(
df, ['Demanded', 'Customer'],
['Start Date', 'End Date'],
value_name='Date'
).drop('variable', 1).set_index('Date')
d1.groupby('Customer').apply(lambda df: df.resample('MS').ffill()) \
.reset_index(0, drop=True) \
.reset_index()
Date Demanded Customer
0 2017-01-01 100 A
1 2017-02-01 100 A
2 2017-03-01 100 A
3 2017-02-01 50 B
4 2017-03-01 50 B
和一个临时表a
,每周六给我一个平均值
"date" "value"
"2016-09-09" 0.0533
"2016-09-12" 0.0552
"2016-09-14" 0.0567
"2016-09-15" 0.0537
"2016-09-19" 0.0529
"2016-09-19" 0.0506
"2016-09-19" 0.0525
"2016-09-20" 0.0517
"2016-09-20" 0.0534
日期几乎从不排队,但有时可能会排队。我想做一个完整的外连接,但mysql不允许它。所以我一直在尝试各种各样的工会和加入,这个问题在过去4个小时里一直在踢我的屁股。我想要的表看起来像这样
b
到目前为止,我有这个什么也没做。
"date" "avgValue"
"2016-09-10" 0.0533
"2016-09-17" 0.0552
"2016-09-24" 0.0522
答案 0 :(得分:0)
我建议使用union all
/ group by
方法:
select date, max(value) as value, max(argvalue) as argvalue
from ((select date, value asvalue, NULL as argvalue from a) union all
(select date, NULL, argvalue from b)
) ab
group by date;