我想創建一個新的csv文件,只有一列來自另一個exsting csv文件。 Python不是隻在csv文件的一列中打印Address,而是將地址分佈在多個列中。我能做些什麼來消除多列問題。從另一個csv文件中創建一個新的csv文件
from __future__ import absolute_import, division, print_function
import csv
from itertools import imap
from operator import itemgetter
def main():
delimiter = ','
with open('C:/Addresses.csv', 'rb') as input_file:
reader = csv.reader(input_file, delimiter=delimiter)
with open('thefirstcolumn.csv', 'wb') as output_file:
writer = csv.writer(output_file, delimiter=delimiter)
writer.writerows(imap(itemgetter(1), reader))
if __name__ == '__main__':
main()
在原始文件:
abcdcolumn Address
********-A-1 6525 Mountain
********-A-2 6543 Mountain
********-A-4 6579 Mountain
********-A-5 6597 Mountain
********-A-6 6615 Mountain
********-A-7 6633 Mountain
在新的CSV文件中的結果:
A d d r e s s
6 5 2 5 M o u n t
6 5 4 3 M o u n t
6 5 6 1 M o u n t
6 5 7 9 M o u n t
6 5 9 7 M o u n t
6 6 1 5 M o u n t
6 6 3 3 M o u n t
可以顯示的原始文件 – Navidad20
可能重複的內容[新列添加到Python中的CSV文件(http://stackoverflow.com/questions/39733158/add-a-new-column -to-A-的CSV文件中的Python) –