Pandas读取两个excel并join

Pandas 的 join就是merge,代码如下

import pandas as pd

#读取两张表

df=pd.read_excel("左表")

#读取右表的第三个sheet中的数据

df2=pd.read_excel("右表",sheet_name="Sheet3")

#以左表为主表,左连接

out=pd.merge(df ,df2 ,on='query' ,how='left')

#写入新的excel文件

out.to_excel("out.xlsx')

针对右测有重复项,担心重复key问题,可以添加一个参数

validate ="one_to_many"

相关推荐
高锰酸钾_1 分钟前
机器学习-L1正则化和L2正则化解决过拟合问题
人工智能·python·机器学习
天天睡大觉23 分钟前
Python学习11
网络·python·学习
智航GIS23 分钟前
11.11 Pandas性能革命:向量化操作与内存优化实战指南
python·pandas
wtsolutions43 分钟前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions1 小时前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
写代码的【黑咖啡】1 小时前
Python中的Selenium:强大的浏览器自动化工具
python·selenium·自动化
抠头专注python环境配置1 小时前
解决Windows安装PythonOCC报错:从“No module named ‘OCC’ ”到一键成功
人工智能·windows·python·3d·cad·pythonocc
华研前沿标杆游学1 小时前
2026年华研就业实践营|走进字节跳动,解锁科技行业职业新航向
python
啊阿狸不会拉杆2 小时前
《数字图像处理》第 4 章 - 频域滤波
开发语言·python·数字信号处理·数字图像处理·频率域滤波
HarmonLTS2 小时前
Pygame动画制作进阶(可直接运行,附核心原理)
python·pygame