我有一个带有名字的exel文件。有些是以斜体存储的,有些是粗体或普通的。斜体的名字是“女性化的”,男性是普通文本,中性的名字是粗体。这份名单大约有6500个名字。我希望能够根据它们在Exel文件中的存储方式来分类不同的类型。
像Print("namn()", 'Female') print(namn(), 'Male')一样
file_name = 'Namn.xlsx' #xlsx file to open
sheet = 'Sheet1' # name of sheet
import pandas as pan
namn = pan.read_excel(io=file_name, sheet_name=sheet)
print(namn.head(10), 'Female') # Print 10 first names in exel file
# problem 1. female names are Italics in the original file but gets printed as regular.
# unisex names are in bold and get printed as normal text in the output.
#
# problem 2. How do I sort out Italics names and Bold names stored in the file.
# 10 first names in the exel file
# Abbe (Normal text in exel file)
# Abe (Normal text in exel file)
# Ada (Italics in exel file)
# Adam (Normal text in exel file)
# Adana (Italics in exel file)
# Adanita (Italics in exel file)
# Adde (Bold in exel file)
# Addison (Bold in exel file)
# Adele (Italics in exel file)
# Adolf (Normal text in exel file)发布于 2020-06-12 20:07:51
可悲的是,目前我不知道如何处理熊猫,我不得不自己深入研究熊猫。但是,您可以使用openpyxl:
import openpyxl as xl
file_path = 'absolute/path/to/your.xlsx'
wb = xl.load_workbook(file_path)
ws = wb.active
#changing to other worksheets:
#ws = wb["Title of the Worksheet"]
a1 = ws['A1']
print(a1.font)# lists the params of font ( i for italic )
print(a1.font.i == True)我刚刚在A1中使用一个包含单个工作表和斜体字符串的.xlsx对其进行了测试。
https://stackoverflow.com/questions/62343416
复制相似问题