【发布时间】:2018-09-14 01:02:32
【问题描述】:
我是 perl 和 python 的新手。
我需要在 python(dataframe) 中处理文件,并且该文件需要在 Perl 中计算。
一开始我尝试使用python子进程,但它不工作(borken pipe)
我需要从python多行,perl代码需要读取和处理。
我只是使用 |在命令行中,它可以工作,但是 perl 跳过了奇数行,只读取了偶数行。
我该如何解决?
我的python代码是:
import pandas as pd
data = pd.read_csv('./data.txt', sep = '\t', header = None)
datalist = list(data[0] + '_' + data[1])
for line in kinase_list:
print(line)
我的 perl 代码是: //
use strict;
my %new_list = ();
while (<STDIN>){
my $line = <STDIN>;
# print STDERR $line;
# chomp $line;
my ($name, $title) = split('_', <STDIN>);
$new_list{$title} = $name;
print STDERR $name, "\t", $title, "\n";
}
print STDERR scalar(keys %new_list);
我的 python 输出 657 行,但 perl 只输出 329 行。
我该如何解决?
【问题讨论】:
-
为什么需要 python 来做这个?看来您只需要前两列,为什么不直接使用
perl,直接从文件中调用两列?即perl -pe "s/((.*?\t)(?2)).*/$1/" C:\users\file1.txt -
还有
my ($name, $title) = split '_'就够了 -
感谢您的回复。我需要编辑 2 个数据框并需要通过特定的 id 合并它并调整两个数据框的一些值。
-
哪个应该调用另一个? python应该调用perl还是perl调用python?我不知道哪个是哪个,但你可以使用
import os;print(os.popen(the_code_above).read()),它也应该可以工作 -
python 打印行,perl 需要读取并使其散列