Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以csv格式导出表格的表格_Python_Export To Csv - Fatal编程技术网

Python 以csv格式导出表格的表格

Python 以csv格式导出表格的表格,python,export-to-csv,Python,Export To Csv,我有四个表,我想使用Python将其导出到单个CSV文件中 这里有一个具体的例子。 假设我有四张这样的桌子: (可能是数组格式。我们可以假设所有四个表都具有相同的形状。) 我想以以下格式导出: (我更喜欢csv格式。) 有人有好主意吗 类似于 # gets you [(['x11','x12','x13'],['y11','y12','y13']),(['x21',...],['y21',...]),...] xy_together = zip(table1, table2) zw_toget

我有四个表,我想使用Python将其导出到单个CSV文件中

这里有一个具体的例子。 假设我有四张这样的桌子: (可能是数组格式。我们可以假设所有四个表都具有相同的形状。)

我想以以下格式导出: (我更喜欢csv格式。)

有人有好主意吗

类似于

# gets you [(['x11','x12','x13'],['y11','y12','y13']),(['x21',...],['y21',...]),...]
xy_together = zip(table1, table2)

zw_together = zip(table3, table4)


# assuming the tables are all the same length...
for i in range(len(xy_together))
    x_row, y_row = xy_together[i]
    print( zip( x_row, y_row ) )

    z_row, w_row = zw_together[i]
    print( zip( x_row, y_row ) )
应该有用


zip()函数接受两个或多个iterable,并生成每个iterable中对应元素的元组列表。

到目前为止您做了什么?
x11, y11, , x12, y12, , x13, y13,   
z11, w11, , z12, w12, , z13, w12,
,,,,,,,,
x21, y21, , x22, y22, , x23, y23,   
z21, w21, , z22, w22, , z23, w23,
,,,,,,,,
x31, y31, , x32, y32, , x33, y33,   
z31, w31, , z32, w32, , z33, w33,
# gets you [(['x11','x12','x13'],['y11','y12','y13']),(['x21',...],['y21',...]),...]
xy_together = zip(table1, table2)

zw_together = zip(table3, table4)


# assuming the tables are all the same length...
for i in range(len(xy_together))
    x_row, y_row = xy_together[i]
    print( zip( x_row, y_row ) )

    z_row, w_row = zw_together[i]
    print( zip( x_row, y_row ) )