2016-09-23 3 views
-1

저는 파이썬에서 처음입니다. 첫 번째 열을 .csv 파일에서 다른 .csv 파일로 복사 할 수 있는지 알고 싶습니다. 그 이유는 .csv가 많아서 수동으로 하나씩 열어서 .csv 파일 하나만 복사하는 대신이 단계를 자동화하고 싶습니다.파이썬으로 CSV에서 CSV로 열 복사하기

대단히 감사합니다!

+0

를 구성해야합니다. 파이썬에는 CSV 구문 분석을위한 특별한 라이브러리 지원이 있습니다. 단지 google입니다. –

+0

절대적으로 가능하며 여러 가지 방법이 있습니다. 시작하려면 표준 lib에있는'csv' 모듈을보십시오. 특정 질문을 게시하는 데 문제가있는 경우 여기를 클릭하십시오. –

+0

먼저 인터넷 검색을 해봤습니까? https://docs.python.org/2/library/csv.html – gonczor

답변

0

코드 Snipet는 : 당신은 당신은 어떤 언어로 파일을 읽을 수있는 것을 할 수있는 소스 및 대상

import os 
from os import listdir 
from os.path import isfile, join 
import csv 

mypath="sourcePath" 
newcsv="destination" 
# for just files in a directory and not the subDirectory 
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] 

print(onlyfiles) 
for file in onlyfiles: 
    if file.endswith(".csv"): 
     with open(os.path.join(mypath,file), newline='') as f: 
      reader = csv.reader(f) 
      for row1 in reader: 

       out = csv.writer(open(newcsv,"w"), delimiter=',',quoting=csv.QUOTE_ALL) 
      out.writerow(row1); 
관련 문제