简体   繁体   中英

Python Combine multiple data frames

I am trying to combine spreadsheets with a common column name (server/instance) however each spreadsheet doesn't have the same number of rows for the common field. Below I outlined the two data frames. I am trying to figure out if this can be output back to to an excel file or use some type of module to create a python GUI.

Data File 1

sever   database    still running
---------------------------------    
test    database1   TRUE
test    database2   TRUE
test2   database1   FALSE
test2   database3   TRUE

Data File 2 (instance is the same as server from DF1)

Instance app name contact
-------------------------
test     app1     harry
test     app2     sally
test     app3     sally
test2    app1     sally

Final output

server  database    still running   app name    contact
-------------------------------------------------------
test    database1   TRUE            app1        harry
test    database2   TRUE            app2        sally
test                                app3        sally
test2   database1   FALSE           app1        sally
test2   database3   TRUE        

I did not understand your logic of merging these spreadsheets, but probably merge from pandas ( https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html ) may be useful. So, firstly you can read these spreadsheets using pandas.read_csv() , then perform merge and in the end save resulting dataframe using pandas.to_csv() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM