python - 我正在尝试用一个公共列映射两个 Excel 工作表,我收到错误声明为属性错误
问题描述
import pandas as pd
#file1 = "mapp1.xlsx"
#file2 = "mapp2.xlsx"
file1 = "C:\\Users\\Sudharshan\\Desktop\\file_map\\mapp1.xlsx"
file2 = "C:\\Users\\Sudharshan\\Desktop\\file_map\\mapp2.xlsx"
df1 = pd.read_excel(file1)
df2 = pd.read_excel(file2)
marge = pd.marge(df1, df2, on="Name")
print(marge)
请在此处提供帮助,执行时出现此错误:
玛吉不是熊猫的属性
我正在尝试使用 Jupyter notebook pycharm 和 google collab
AttributeError
Traceback(最近一次调用最后一次)在10 df2 = pd.read_excel(file2)
11
---> 12 marge = pd.marge(df1, df2, on="Name")
13
14 print(marge)~\anaconda3\lib\site-packages\pandas_init _.py in getattr (name)
256 return _SparseArray
257
--> 258 raise AttributeError(f"module 'pandas' has no attribute '{name}'")
259
260AttributeError:模块'pandas'没有属性'marge'
解决方案
您的代码中有错字。我认为应该是 pd.merge 而不是 pd.marge
也用于组合两个excel表列...
尝试这个:
假设您的工作簿 1 或 excel 文件 1 有四列,分别名为“Locations”、“Employees”、“Revenue”和“Profit”。你的 excel 文件 2 也有所有这些列和一些额外的列。现在您要合并 output.xlsx 中两个文件中的这四列
所以,你可以这样做:
import pandas as pd
excel1 = 'workbook1.xlsx'
excel2 = 'workbook2.xlsx'
df1 = pd.read_excel(excel1)
df2 = pd.read_excel(excel2)
values1 = df1['Locations','Employees','Revenue','Profit']
values2 = df2['Locations','Employees','Revenue','Profit']
dataframes = [values1, values2]
join = pd.concat(dataframes)
join.to_excel("output.xlsx")
推荐阅读
- c# - 在主机上上传图像的访问被拒绝
- arrays - 将数组对象附加到powershell中的数组对象
- javascript - div 离开身体,宽度更大
- laravel - 在 laravel 8 上使用 brozat/laravel-FCM 的问题
- android - 通过不同的 DAO 访问数据库
- android-sharing - 分享失败请在android studio中重试
- sql - 选择不在两个日期之间的日期范围内的数据
- python - 在底部的 Dataframe 上插入一行并计算总和
- python - 如何从表中抓取特定的 td 标签?
- javascript - 对 js 中的原型链行为感到困惑