Python 2D 数字列表到 csv



我正在寻找将 2D 列表转换为包含每个点的坐标 (xyz( 的 csv 文件的最佳方法。

2D 列表具有以下格式:

['586.732'], ['626.012'], ['496.778']
['597.422'], ['536.778'], ['586.056']
['597.422'], ['536.778'], ['586.056']

用:

with open("output.csv", "w") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows([x, y, z])

将返回一个转置的对象列表,该列表不容易绘制。

如果有人能提出解决这个问题的方法,我会很高兴。

使用 zip() 将执行您想要的操作。

with open("output.csv", "w") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows( zip(x, y, z) )

csv 将看起来像

x1, y1, z1
x2, y2, z2
x3, y3, z3
...

最新更新