0

InputfilesListInplane文件目录,我可以选择多个数据并从它们各自的文件夹中获取结果。 在此处输入图像描述

每次提取 1 个数据时,我的程序都会提取 FieldIP 和 SignalIP。它看起来像这样

Extracted FieldIP and SignalIP (SignalIP contains more data than FieldIP)
FieldIP = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16...]
SignalIP = [1,2,3,4,5,6,7,8,9,10,12,20,40...] 

我尝试过的代码,但数据只是保持垂直堆叠。

newfile = "C:/VSMPlots/TabulatedStatsVSM.csv"
with open(newfile, "wb") as csvfile:
    for file_path_IP in InputfilesListInplane: 
        writer = csv.writer(csvfile)
        writer.writerow(["FieldIP", "SignalIP"])
        writer.writerow([" "])
        for field, signal in zip(FieldIP, signalIP):
            writer.writerow([field,signal])
        writer.writerow("")

我的代码将以这种格式显示

在此处输入图像描述

我怎样才能把它变成这种格式

在此处输入图像描述

4

1 回答 1

0
import numpy as np

a = np.asarray([[1,2,3], [4,5,6], [7,8,9]])
np.savetxt("foo.csv", a, delimiter=",")

上面的代码会给你:

1 2 3
4 5 6
7 8 9

所以基本上,从文件中读取所有数据,将它们排列在a.

import numpy as np

dat1 = np.genfromtxt('foo1', delimiter=',')
dat2 = np.genfromtxt('foo2', delimiter=',')

a = np.hstack((dat1, dat2))

np.savetxt("foo.csv", a, delimiter=",", fmt="%d")

认为:

foo1:             foo2:
1,2               3,4
1,2               3,4
1,2               3,4

上面的代码给你:

1,2,3,4
1,2,3,4
1,2,3,4
于 2013-11-14T02:18:11.940 回答