通过Python从Excel工作表中提取单词

2024-09-29 01:25:48 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用Python从Excel中提取单词并使其成为单独的列? 例如:blow文本在excel表格中,我想提取“血型”并使其成为新的克隆

血型-O阳性,HIV/HBsAg/HCV-阴性


Tags: 文本阳性单词excel表格hiv阴性blow
2条回答

这取决于你到底想提取什么。如果是allways血型,那么你可以只使用一个切片,如果你想提取的是不同的单词,那么你需要提供更多的细节,以便任何人能够正确地帮助你

让我知道更多的细节是什么,你正在寻找

因此,假设您的数据如下所示: enter image description here

我们可以做到:

import pandas as pd

data = pd.read_csv('doc.csv')

得到 enter image description here

最后

split_by_comma = data.col1.str.split(',').tolist()
blood_group = [lst[0].split('- ')[1] for lst in split_by_comma]
hiv         = [lst[1].split('- ')[1] for lst in split_by_comma]
pd.DataFrame({'Blood Group': blood_group, 'HIV/HBsAg/HCV': hiv})

要获得此信息: enter image description here

相关问题 更多 >