首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何测试列表是否包含斜体或粗体文本?

如何测试列表是否包含斜体或粗体文本?
EN

Stack Overflow用户
提问于 2020-06-12 19:32:33
回答 1查看 46关注 0票数 0

我有一个带有名字的exel文件。有些是以斜体存储的,有些是粗体或普通的。斜体的名字是“女性化的”,男性是普通文本,中性的名字是粗体。这份名单大约有6500个名字。我希望能够根据它们在Exel文件中的存储方式来分类不同的类型。

Print("namn()", 'Female') print(namn(), 'Male')一样

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2020-06-12 20:07:51

可悲的是,目前我不知道如何处理熊猫,我不得不自己深入研究熊猫。但是,您可以使用openpyxl

代码语言:javascript
复制
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对其进行了测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62343416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档