转置CSV文件

时间:2018-10-29 06:20:38

标签: python-3.x csv

我的目标:

我有一个csv文件,我想一起更改行及其列的内容(转置它)

我做什么:

我使用izip如下:

import csv
from itertools import izip

a = izip(*csv.reader(open("my_file.csv", "rb")))
csv.writer(open("output.csv", "wb")).writerows(a)

我的错误:

我遇到以下错误:

Traceback (most recent call last):
  File "TransposeCSV.py", line 2, in <module>
    from itertools import izip
ImportError: cannot import name 'izip'

我的问题:

出了什么问题,或者有另一种方式转置我的csv文件?

2 个答案:

答案 0 :(得分:1)

我想您已经找到了与此相关的Python 2教程,并且正在使用Python 3进行尝试?在Python 3中,您可以使用zip与Python 2中的itertools中的izip几乎一样,甚至具有更好的性能。

答案 1 :(得分:1)

<FrameLayout android:layout_width="0dp" android:layout_weight="0.25" android:layout_height="wrap_content"> <View android:layout_width="match_parent" android:background="@color/aub_red" android:layout_height="match_parent"/> <ImageButton android:id="@+id/button_scan" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="4dp" android:backgroundTintMode="screen" /> </FrameLayout> 仅在izip包下的Python 2中可用。在Python 3中,可以通过itertools内置函数使用相同的功能。

相关问题