2017-09-05 19 views
3

我想通過datetime合併兩個數據幀;然而,當有一個重複的日期時間,我想將它們放在不同的行,而不是合併到同一行: 即Python合併數據幀left_only&right_only

0 2016-10-03 11:00:00 Trade 5.0 Quote 86.70 both 
1 2016-10-03 11:00:01 NaN NaN Quote 86.71 right_only 

第一行,我想「交易」和「報價」分成兩行:

0 2016-10-03 11:00:00 Trade 5.0 NA Na  both 
0 2016-10-03 11:00:00 Na Na Quote 86.70 both 

是不是有 '兩個' 中的各項指標,我想left_only和right_only 我當前的代碼:

table1 = BuyData1[['Time', 'Type','Volume']] 
table1.set_index(['Time'], drop=True) 
table2 = Quote_data3[['Time','Type','Price']] 
table2.set_index(['Time'], drop=True) 
table3 = pd.merge(table1,table2,on = 'Time', how = 'outer',sort = True, copy=True, indicator=True) 

回答

2

table1.append(table2, ignore_index=True).sort_values('Time') 
+0

非常感謝, – bing

+1

你的思維能力越來越強;-) – MaxU