[英]pandas to_excel converts _x10e6 _ to ღ. How do I avoid this?
我一直在嘗試創建一個 excel 文件,其中包含來自增量表的幾張表,但是我的一些列名包括 _x10e6 _ 這顯然被翻譯為ღ。 我嘗試使用 encoding='unicode_escape' 和 encoding='utf-8' 沒有運氣。 我無法使用 xlsxwriter,因為我要附加到現有文件。
有人知道我如何將 _x10e6 _ 保留在列名中嗎?
我正在使用的部分代碼:
goldDF = spark.read.format('csv')\
.option('header', True)\
.option('delimiter', ',')\
.load(file_path)
pandaDF = goldDF.toPandas()
with pd.ExcelWriter('/tmp/output.xlsx',mode='a', engine='openpyxl') as writer:
pandaDF.to_excel(writer, sheet_name=name, index=False)
dbutils.fs.cp("file:/tmp/output.xlsx", "/mnt/delta_lake_path")
問題是_x10e6_
是字符 0x10E6 的 XML 轉義碼,相當於Unicode 字符“ღ”。
在類似的情況下, Excel 會將其轉義為_x005F_x10e6_
。 看起來 openpyxl 沒有這樣做,因此您可以使用字符串_x005F_x10e6_
手動執行此操作,或者(對於不受 append 模式要求約束的任何閱讀本文的人)將“引擎”切換到 xlsxwriter,這將自動轉義它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.