2016-12-28 97 views
0

我是熊貓數據框的新手,並且有以下問題。結合三個數據幀

我有3個dataframes讀取CSV文件來:

  • 數據幀1被命名爲pdDop,並具有以下條目:

    DOP_WNC DOP_TOW DOP_NRSVS DOP_PDOP DOP_VDOP DOP_HDOP DOP_TDOP 
    
    1928 424800.0   4  5.81  5.36  2.24  2.72 
    
    1928 424801.0   4  5.81  5.36  2.24  2.72 
    
    1928 424802.0   4  5.80  5.35  2.24  2.72 
    
    1928 424803.0   4  5.80  5.35  2.24  2.72 
    
    1928 424804.0   4  5.80  5.35  2.24  2.72 
    
    1928 424805.0   4  5.80  5.35  2.24  2.72 
    
  • 數據幀2被命名爲pdGeod,並具有以下條目:

    GEOD_TOW GEOD_MODE GEOD_2D/3D GEOD_Error GEOD_NrSV GEOD_Latitude GEOD_Longitude GEOD_Height 
    
    424800.0   1   0   0   4   0.8874   0.0767  150.4975 
    
    424801.0   1   0   0   4   0.8874   0.0767  150.5277 
    
    424802.0   1   0   0   4   0.8874   0.0767  150.5579 
    
    424803.0   1   0   0   4   0.8874   0.0767  150.5931 
    
    424804.0   1   0   0   4   0.8874   0.0767  150.6214 
    
  • 個數據幀3被稱爲pdSatVis,做出如下條目:

    VISIBILITY_TOW VISIBILITY_SVID VISIBILITY_AZIMUTH VISIBILITY_ELEVATION 
    
    426175.0    92    54.50     35.43 
    
    426175.0    100    108.22     26.00 
    
    426175.0    88    49.29     10.48 
    
    426175.0    89    278.29     17.39 
    
    426176.0    92    54.50     35.43 
    
    426176.0    100    108.22     26.00 
    
    426176.0    88    49.29     10.48 
    
    426176.0    89    278.29     17.39 
    
    426177.0    92    54.48     35.42 
    
    426177.0    100    108.23     25.98 
    
    426177.0    88    49.28     10.45 
    
    426177.0    89    278.27     17.38 
    
    426178.0    92    54.48     35.42 
    

我想創建它集基於所述*_TOW(周時)柱,其是在每個數據幀1個數據幀。注意最後一個數據幀pdSatVis有幾行,VISIBILTY_TOW的值只對應於pdDoppdGeod中的1行。

回答

0

您可以添加新列合併上:

pdDop['TOW'] = pdDop['DOP_TOW'] 
pdGeod['TOW'] = pdGeod['GEOD_TOW'] 
pdSatVis['TOW'] = pdSatVis['VISIBILITY_TOW'] 
pd.merge(pd.merge(pdDop, pdGeod, how='outer'), pdSatVis, how='outer') 

或提供的列明確合併於:

m1 = pd.merge(pdDop, pdGeod, how='outer', left_on='DOP_TOW', right_on='GEOD_TOW') 
pd.merge(m1, pdSatVis, how='outer', left_on='DOP_TOW', right_on='VISIBILITY_TOW')