从文件中的两个匹配项之间提取Python中的数据

问题描述 投票:-2回答:1
Table 1 Qualitative composition of SERQUEL 25 mg tablets 
Ingredient  Function    Reference to standards
Tablet core     
Quetiapine fumarate Drug substance  This document
Povidone    Binder  USP
Dibasic calcium phosphate dihydrate Diluent USP
Microcrystalline cellulose  Diluent USNF
Sodium starch glycolate Disintegrant    USNF
Lactose monohydrate Diluent USNF
Magnesium stearate  Lubricant   USNF
Purified water  Granulating vehicle USP

以上表示来自.txt文件的示例数据:

我有一个要匹配的物质名称列表。(csv文件中的物质示例为'Quetiapine fumarate', 'Povidone', 'Magnesium stearate' etc etc.)我将它们存在于csv文件中。我想迭代文本文件的每一行,并创建从一种物质到另一种物质的组。输出示例:

['Quetiapine fumarate   Drug substance  This document'],
['Povidone  Binder  USP'],
['Lactose monohydrate   Diluent USNF'],
['Magnesium stearate    Lubricant   USNF']

假设我的csv物质清单中包含“富马酸喹硫平”,“聚维酮”,“一水乳糖”,“硬脂酸镁”。

如何在Python中执行此操作

python regex loops csv string-matching
1个回答
0
投票
file = open(FOLDER_NAME + '/' + name, 'r', encoding='utf-8') data = file.readlines() for line in data: words=line.split() print(words)

您可以搜索'从python文件中读取'

https://www.w3schools.com/python/python_file_open.asp

© www.soinside.com 2019 - 2024. All rights reserved.