我有一个像:[(15932, 2.9, 1), (15430, 3.6, 0), (16712, 10.9, 1), (15890, 6.6, 1)]
这样的元组列表,如何将其转换为以下DataFrame结构:
15932 2.9 1
15430 3.6 0
16712 10.9 1
15890 6.6 1
答案 0 :(得分:2)
这样简单,使用默认构造函数。
pd.DataFrame.from_records([(15932, 2.9, 1), (15430, 3.6, 0), (16712, 10.9, 1), (15890, 6.6, 1)])
或者使用替代构造函数。
awk 'BEGIN{FS=OFS=","; out=ARGV[1] ".removed.index"}
FNR==NR {
for (i=1; i<=NF; i++)
sums[i] += $i;
++r;
next
} FNR==1 {
for (i=3; i<=NF; i++) {
if (sums[i] == 0) {
if (i-1 in sums) {
delete sums[i-1];
print "removed index: " (i-1) > out
}
delete sums[i];
print "removed index: " i > out
} else if (sums[i] == 100*r) {
delete sums[i];
print "removed index: " i > out
}
}
} {
printf "%s", $1
for (i=2; i<=NF; i++)
if (i in sums)
printf "%s%s", OFS, $i;
printf "%s", ORS
} END{close(out)}' file file