I used the flow that I often used when I wanted to combine and concatenate Excel and CSV based on each specific column as a function.
As a flow
Below is a summary of the arguments and the code.
| variable | explaination |
|---|---|
| a | The one you want to put on the left in the files you want to combine |
| b | The one you want to put on the right in the files you want to combine |
| left_on | Column name of the column you want to use as the reference for a |
| right_on | Column name of the column you want to use as the reference for b |
| how | inner: Combined leaving only the common ones left: a will definitely remain, leaving only the common b right: b is absolutely left, leaving only the common ones of a outer: leave everything |
| where_name | Absolute path to save the combined files |
in
import pandas as pd
def merge_2Excelfiles(a,b,left_on,right_on,how,where_name):
df_a = pd.read_excel(a)
df_b = pd.read_excel(b)
c = pd.merge(df_a, df_b, left_on=left_on, right_on=right_on, how=how,)
c.to_excel(where_name)
return c
Recommended Posts