Python Merge Tables: Combine Data with Pandas

In Python, you can use the pandas library to merge multiple tables into one. Here is a simple example code:

import pandas as pd

# 读取多个表格数据
df1 = pd.read_excel('data1.xlsx')
df2 = pd.read_excel('data2.xlsx')

# 合并表格
df = pd.concat([df1, df2], ignore_index=True)

# 保存合并后的表格数据
df.to_excel('merged_data.xlsx', index=False)

In the example above, multiple tables of data are first read using the pd.read_excel() method, then these tables are merged into a new data frame using the pd.concat() method, and finally the merged data is saved into a new Excel file using the to_excel() method.

bannerAds