我正在使用Python中的大数据集,通过Pandas。我有一个包含感兴趣的标识符的文件和一个数据文件,其中的行可能与这些标识符匹配,也可能不匹配。在
我写了一段代码,它使用第一个文件中的标识符来查找与第二个文件中的标识符匹配的数据行。该代码当前将感兴趣的行输出到终端(通过“print”)。我想把代码找到的数据行加载到一个数据帧中,这样输出就可以被写入一个csv文件(通过pandas.to\u csv),但不确定如何继续。在
以下是目前的代码:
for i in range(0, len(egg.index)):
#selects datum in file1 as search term
identifier = egg.ix[i,0]
for j in range(0, len(b.index)):
#searches file2 for row indexed by identifier
if identifier in b.ix[j, "SAMPLE_ID"]:
print b.ix[j]
#prints row to console
outputdf = concat(b.ix[j])
#should concatenate row to a fresh dataframe for output; fails
谢谢!在
将行追加到现有文件。在
(我想把这句话放在你问题的评论中,但我没有足够的声誉这么做。)
相关问题 更多 >
编程相关推荐