[Python] I want to merge Excel files anyway (pandas.merge)

Combine excel files

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

  1. Load the two Excel files you want to combine as pandas.DataFrame
  2. Merge with pandas.merge ()
  3. Save the combined data as an Excel file
  4. Returns the combined data

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

[Python] I want to merge Excel files anyway (pandas.merge)
I want to merge nested dicts in Python
I want to debug with Python
I want to use jar from python
I want to build a Python environment
I want to analyze logs with Python
I want to play with aws with python
I want to color a part of an Excel string in Python
I want to do Dunnett's test in Python
I want to memoize including Python keyword arguments
I want to create a window in Python
Anyway, I want to check JSON data easily
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to make a game with Python
I want to visualize csv files using Vega-Lite!
I want to use Temporary Directory with Python2
I want to use ceres solver from python
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
Batch conversion of Excel files to JSON [Python]
I want to sell Mercari by scraping python
[Python] I want to manage 7DaysToDie from Discord! 2/3
I want to make C ++ code from Python code!
I want to write to a file with Python
I want to display the progress in Python!
I want to get / execute variables / functions / classes of external files from Python
[Python] I want to collect specific files scattered in each folder in one place
I want to write in Python! (1) Code format check
Even beginners want to say "I fully understand Python"
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to iterate a Python generator many times
I want to generate a UUID quickly (memorandum) ~ Python ~
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I want to randomly sample a file in Python
I want to inherit to the back with python dataclass
I want to work with a robot in python.
[Python3] I want to generate harassment names from Japanese!
[Python] I want to make a nested list a tuple
I want to write in Python! (3) Utilize the mock
I want to AWS Lambda with Python on Mac!
[ML Ops] I want to do multi-project with Python
I want to use the R dataset in python
I want to run a quantum computer with Python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
I want to solve Sudoku (Sudoku)
I want to be able to analyze data with Python (Part 3)
I want to initialize if the value is empty (python)
I want to specify another version of Python with pyvenv
maya Python I want to fix the baked animation again.
I want to be able to analyze data with Python (Part 1)
I want to do something like sort uniq in Python
[Python] I want to get a common set between numpy
I want to start a lot of processes from python
I want to be able to analyze data with Python (Part 4)
I want to be able to analyze data with Python (Part 2)
I want to automatically attend online classes with Python + Selenium!
[Python] I want to use the -h option with argparse