[英]Python 2D list of numbers to csv
Im looking for the best way to convert a 2D list to csv file containing the coordinates (xyz) for every point. 我正在寻找将2D列表转换为包含每个点坐标(xyz)的csv文件的最佳方法。
The 2D-list has this format: 2D列表具有以下格式:
['586.732'], ['626.012'], ['496.778']
['597.422'], ['536.778'], ['586.056']
['597.422'], ['536.778'], ['586.056']
Using: 使用方法:
with open("output.csv", "w") as csvfile:
writer = csv.writer(csvfile)
writer.writerows([x, y, z])
will return a transposed list of objects, that cannot be plotted easily. 将返回对象的转置列表,该列表不容易绘制。
I would be happy if anyone could suggest a way to solve this. 如果有人可以提出解决方案,我将很高兴。
Using zip()
will do what you want. 使用zip()
可以满足您的需求。
with open("output.csv", "w") as csvfile:
writer = csv.writer(csvfile)
writer.writerows( zip(x, y, z) )
The csv will look like CSV看起来像
x1, y1, z1
x2, y2, z2
x3, y3, z3
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.