2016-06-22 2 views
0

이 스크립트는 다른 스택 오버플로 게시를 기반으로 작동하고 있으며 원하는 작업을 수행하는 데 너무 가깝습니다. 마지막 단계는 새 CSV를 인수로 추가하는 두 번째 위치에 저장하는 것입니다. 이 코드에서 "removed.csv"를 대상으로 바꾸고 싶지만 작동하지 않습니다. 소스 코드가있는 곳에서 저장하고 저장 위치를 ​​지정하고 싶습니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니까? 정말 고마워!Python Pandas as pd set to_csv 위치

#!/usr/bin/python 

import sys 

import pandas as pd 

filename = sys.argv[1] 
destination = sys.argv[2] 

df = pd.read_csv(filename) 

keep_cols = ["Path", "IPTC - Title", "Description", "Person(s) of Import", "Museum Location", "Catalog Name", "Catalog Number", "Catalog Link", "Keywords", "Special Exhibitions", "Donor Credit", "Video Licensing", "Image Licensing", "Music Licensing", "Audio Licensing", "Relate Assets", "IPTC - Creator", "IPTC - City", "IPTC - Country", "Rights Usage Terms"] 

new_df = df[keep_cols] 

new_df.to_csv("removed.csv", index=False) 

답변

0

정확한 경로를 설정할 수 있습니다.

에서와 마찬가지로이 같은

new_df.to_csv(r"C:\users\mthiesen\desktop\python\removed.csv", index=False) 

또는 무언가 :

path_to_output = r'C:\Users\clickhere\Desktop' 
new_df.to_csv(path_to_output + r'\output.csv') 

참고 : 당신은 또한 단지 당신이 라를 필요로하는 컬럼에 복용하여 성능을 향상시킬 수 :

keep_cols = ["Path", "IPTC - Title", "Description", "Person(s) of Import", "Museum Location", "Catalog Name", "Catalog Number", "Catalog Link", "Keywords", "Special Exhibitions", "Donor Credit", "Video Licensing", "Image Licensing", "Music Licensing", "Audio Licensing", "Relate Assets", "IPTC - Creator", "IPTC - City", "IPTC - Country", "Rights Usage Terms"] 
new_df = pd.read_csv(filename,usecols=keep_cols) 
+0

고마워요! 이것은 일했다 :) –