我爲工作日以下數據框傳播值大熊貓失蹤日期
In [23]: d = pd.DataFrame({'date' : ['20070105', '20070105', '20070106', '20070106', '20070106', '20070109'], 's' : [1, 2, 1,2,3,1], 'i': ['a', 'b', 'a', 'b', 'c', 'a']})
In [26]: d['date'] = pd.to_datetime(d['date'], format='%Y%m%d')
In [27]: d
Out[27]:
date i s
0 2007-01-05 a 1
1 2007-01-05 b 2
2 2007-01-06 a 1
3 2007-01-06 b 2
4 2007-01-06 c 3
5 2007-01-09 a 1
我想在數據填寫(根據「奧爾代斯」日曆)失蹤日期和輸出應該是如下。基本上20070107和20070108失蹤,其數據來自20070106.
Out[31]:
date i s
0 2007-01-05 a 1
1 2007-01-05 b 2
2 2007-01-06 a 1
3 2007-01-06 b 2
4 2007-01-06 c 3
5 2007-01-07 a 1
6 2007-01-07 b 2
7 2007-01-07 c 3
8 2007-01-08 a 1
9 2007-01-08 b 2
10 2007-01-08 c 3
11 2007-01-09 a 1
什麼是大熊貓做到這一點的最佳方式複製?
請參閱[如何使重複性好大熊貓的例子(http://stackoverflow.com/questions/20109391/how-to- make-good-reproducible-pandas-examples)並相應地編輯你的文章。在輸入和輸出數據集中使用日期而不是字符串 – MaxU
謝謝。增加了可重複的代碼。 – Man