大佬教程收集整理的这篇文章主要介绍了Pandas 数据框中的单元格具有 Excel 工作簿中不存在的异常符号,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Pandas 来比较从两个 Excel 工作簿中提取的两个大数据框,在合并和比较差异后,我注意到未合并的单元格有不寻常的重音和商标符号,它们没有在 Excel 工作簿中。我推测这些符号是合并没有发生的原因,但我不确定它们为什么会出现在 Pandas 数据框中,或者如何摆脱它们/让它们被识别。
我不确定这是 Python 中的编码问题,还是 Excel --> Python 中的导入问题。
符号仅出现在数据帧的一列中,称为“com_it”。我尝试使用以下方法替换符号,但没有用:
com['com_it'].replace(u"\u00AE",'',inplace=TruE)
pano2['com_it'].replace(u"\u00AE",inplace=TruE)
任何有关如何使符号消失或以其他方式合并这些单元格的帮助将不胜感激!
pandas 如何处理和解释 excel 文件的字符编码是一个问题。不确定 ['com_it'] 中的数据类型。最初导入 Excel 工作簿时,请尝试以下两个选项。我相信选项 1 将解决您的问题。如果没有,请尝试选项 2。
选项 1
尝试在创建数据帧时将引擎定义为 openpyxl。
onmouseenter
确保你的 pandas/numpy 是最新的并且你已经安装了 openpyxl。
array_x = np.array([1,2,3])
array_y = np.array([1,3])
array_z = np.array([1,3])
array3D = something
for ix,x in enumerate(array_X):
for iy,y in enumerate(array_y):
for iz,z in enumerate(array_z):
array3D[ix][iy][iz] *= x*y*z
PyPi openpyxl
选项 2
在创建数据帧文件时传递字符编码。
import pandas as pd
com = pd.read_excel(excel_file_path,ENGIne='openpyxl')
pano2 = pd.read_excel(excel_file_path,ENGIne='openpyxl')
,
非常感谢您!我一直在使用 tk 接口来自动拉取文件,而不是直接将它们输入到代码中。当我使用它运行选项 2 时,它产生了一个错误。我已经粘贴了下面的代码。还有另一种编码 UTF-8 的方法吗?
import pandas as pd
import numpy as np
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.utils.dataframe import dataframe_to_rows
from openpyxl import load_workbook
from openpyxl.worksheet.table import Table
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import xlrd
import test_functions as tf
import String
## UI - Asking user for their input and output files
root = tk.Tk()
root.withdraw()
root.pano2 = filedialog.askopenfilename(initialdir = "C:/",@R_673_10283@e = "SELEct the LOCATIOn of your Pano file",filetypes = (("Excel Files","*.xLSX"),("all files","*.*")))
root.com = filedialog.askopenfilename(initialdir = "C:/",@R_673_10283@e = "SELEct the LOCATIOn of your Com file","*.*")))
root.save_LOCATIOn = filedialog.asksaveasfilename(initialdir = "C:/",@R_673_10283@e = "Input name of file to be saved",defaultextension = ".xLSX","*.*")))
# ## ImporTing datasets
pano2 = pd.read_excel(root.pano2,encoding = 'utf-8')
com = pd.read_excel(root.com,encoding = 'utf-8')
以上是大佬教程为你收集整理的Pandas 数据框中的单元格具有 Excel 工作簿中不存在的异常符号全部内容,希望文章能够帮你解决Pandas 数据框中的单元格具有 Excel 工作簿中不存在的异常符号所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。