我试图找出如何将文本文件中的标记与excel文件中的数据进行比较。 我把文本转换成一个元组列表,我可以从csv文件中读取数据,看起来像这样(但要大得多):
name score1 score2 score3
arm 1 2 3
beard 4 5 6
chin 7 8 9
我把文本变成了一个元组列表,看起来像这样:
[(0, 'My'), (1, 'arm'), (2, 'has'), (3, 'no'), (4, 'chin'), (5, '.')]
我想做的是迭代数据文件中的名称,返回相应的分数并从中创建一个新列表:
[(0, 'My'), (1, 'arm', 1, 2, 3), (2, 'has'), (3, 'no'), (4, 'chin', 7, 8, 9), (5, '.')]
我能读出某一行的分数
import pandas as pd
data = pd.read_csv('datafile.csv')
names = data[:1][['score1', 'score2', 'score3']]
我还可以检查这些名称中的特定单词:
names.str.contains("arm")
我现在的问题是,我既不知道如何检索非特定名称(不仅仅是data[:1]
)的分数,也不知道如何检索iterable变量的分数。我也不知道如何在我的文本中检查任何字符串。你知道吗
编辑更改了csv文件
您的用例非常简单,我建议不要使用外部库(当然除了漂亮的打印…)。你知道吗
代码被注释,它产生的输出也被注释。。。你知道吗
将上述内容保存到一个文件中并执行,得到了以下oputput
编辑:显示预期输出的交互式会话
我删去了评论和大部分打印件。你知道吗
相关问题 更多 >
编程相关推荐