我正在尝试更正没有日期的每一行。然后想法只是填补缺失日期之间的空白,并用以前的值完成其他列。 ds SKU Estoque leadtime0 2018-01-02 504777 45 111 2018-01-04 504777 42 112 2018-01-05 504777 41 113 2018-01-09 504777 40 114 2018-01-12 504777 37 115 2018-01-13 504777 36 116 2018-01-15 504777 35 11... ... ... ... ...6629 2018-08-14 857122 11 106630 2018-08-15 857122 10 106631 2018-08-16 857122 9 106632 2018-08-17 857122 7 106633 2018-08-23 857122 14 106634 2018-08-24 857122 13 10我已经尝试过:df.set_index('ds', inplace=True)df = df.resample("D")或者df.resample("D", how='first', fill_method='ffill')但我刚得到这个:DatetimeIndexResampler [freq=<Day>, axis=0, closed=left, label=left, convention=start, base=0]当我尝试:(df.groupby('SKU') .resample('D') .last() .reset_index() .set_index('ds'))我收到此错误:ValueError: cannot insert SKU, already exists我试图得到这个结果: ds SKU Estoque leadtime0 2018-01-02 504777 45 111 2018-01-03 504777 45 112 2018-01-04 504777 42 113 2018-01-05 504777 41 114 2018-01-06 504777 41 115 2018-01-07 504777 41 116 2018-01-08 504777 41 117 2018-01-09 504777 40 11... ... ... ... ...PS:如果我将日期设置为索引,我有重复的索引。我需要首先隔离每个产品(分组依据)
1 回答

慕勒3428872
TA贡献1848条经验 获得超6个赞
在您的情况下,您可能需要与 apply
#df.set_index('ds', inplace=True)
df.groupby('SKU').apply(lambda x : x.resample('D').ffill()).reset_index(level=0,drop=True)
添加回答
举报
0/150
提交
取消