合并具有不同订单列的多个Dataframe

时间:2018-02-26 06:11:16

标签: pandas dataframe merge

我有三个pandas.Dataframe像这样:

df1
    A_1 A_2 A_3 
MAC                                                     
ID1 1.0 1.0 2.0 
ID2 6.0 6.0 7.0 
ID3 1.0 2.0 3.0 

df2
    B_1 B_2 B_3 
MAC                                                     
ID1 1.0 1.0 1.0 
ID2 2.0 2.0 3.0 
ID3 1.0 1.0 1.0 

df3
    C_1 C_2 C_3 
MAC                                                     
ID1 1.0 1.0 2.0 
ID2 5.0 5.0 5.0 
ID3 1.0 2.0 3.0 

我想pd.mergepd.concat预期结果如下:

MAC A_1 B_1 C_1 A_2 B_2 C_2 A_3 B_3 C_3
ID1 1.0 1.0 1.0 1.0 1.0 1.0 2.0 1.0 2.0
ID2 6.0 2.0 5.0 6.0 2.0 5.0 7.0 3.0 5.0
ID3 1.0 1.0 1.0 2.0 1.0 2.0 3.0 1.0 3.0

我在这个链接中搜索了https://pandas.pydata.org/pandas-docs/stable/merging.html,但结果并不像我预期的那样。 提前感谢您的回答。

1 个答案:

答案 0 :(得分:2)

我认为您需要使用自定义INFO: Scanner configuration file: C:\SonarQube\sonar-scanner-3.0.3.778-windows\bin\..\conf\sonar-sca nner.properties INFO: Project root configuration file: D:\DELPHI\Python-Scripts\getjirareleaseinfo\sonar-project.pro perties INFO: SonarQube Scanner 3.0.3.778 INFO: Java 1.8.0_121 Oracle Corporation (64-bit) INFO: Windows 7 6.1 amd64 INFO: User cache: C:\Users\20124457\.sonar\cache INFO: Load global repositories INFO: Load global repositories (done) | time=369ms INFO: User cache: C:\Users\20124457\.sonar\cache INFO: Load plugins index INFO: Load plugins index (done) | time=41ms INFO: SonarQube server 5.6.7 INFO: Default locale: "en_IN", source code encoding: "windows-1252" (analysis is platform dependent) INFO: Process project properties INFO: Load project repositories INFO: Load project repositories (done) | time=129ms INFO: Load quality profiles INFO: Load quality profiles (done) | time=86ms INFO: Load active rules INFO: Load active rules (done) | time=2119ms WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project. INFO: Publish mode INFO: ------------- Scan getjirareleaseinfo INFO: Language is forced to py INFO: Load server rules INFO: Load server rules (done) | time=502ms INFO: Base dir: D:\<dir1>\<dir2>\getjirareleaseinfo INFO: Working dir: D:\<dir1>\<dir2>\getjirareleaseinfo\.scannerwork INFO: Source paths: . INFO: Source encoding: windows-1252, default locale: en_IN INFO: Index files INFO: 1 files indexed INFO: Quality profile for py: Sonar way INFO: JaCoCoSensor: JaCoCo report not found : D:\<dir1>\<dir2>\getjirareleaseinfo\target\jac oco.exec INFO: JaCoCoItSensor: JaCoCo IT report not found: D:\<dir1>\<dir2>\getjirareleaseinfo\target \jacoco-it.exec INFO: Sensor Lines Sensor INFO: Sensor Lines Sensor (done) | time=10ms INFO: Sensor PythonXUnitSensor INFO: Sensor PythonXUnitSensor (done) | time=16ms INFO: Sensor SCM Sensor INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specif y it. INFO: Sensor SCM Sensor (done) | time=4ms INFO: Sensor Python Squid Sensor INFO: Python unit test coverage INFO: Python integration test coverage INFO: Python overall test coverage INFO: Sensor Python Squid Sensor (done) | time=453ms INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=10ms INFO: Sensor Code Colorizer Sensor INFO: Sensor Code Colorizer Sensor (done) | time=1ms INFO: Sensor CPD Block Indexer INFO: DefaultCpdBlockIndexer is used for py INFO: Sensor CPD Block Indexer (done) | time=35ms INFO: Calculating CPD for 1 files INFO: CPD calculation finished INFO: Analysis report generated in 60ms, dir size=101 KB INFO: Analysis reports compressed in 19ms, zip size=28 KB INFO: Analysis report uploaded in 121ms INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/my:getjirareleaseinf o1 INFO: Note that you will be able to access the updated dashboard once the server has processed the s ubmitted analysis report INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWHVtRKYC92AFUo5IKT6 INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 8.724s INFO: Final Memory: 46M/227M INFO: ------------------------------------------------------------------------ 功能的concat reindex

lambda