-1
일부 csv 파일을 세로로 연결하는 프로그램을 작성했습니다. 여기에 프로그램이 있습니다.연결 스크립트를 실행할 때 "오류 21 : 디렉터리입니다"
import os
import glob
import pandas
def concatenate(indir, outfile, colnames):
os.chdir(indir)
fileList=glob.glob('*.csv')
dfList=[]
for filename in fileList:
print(filename)
df=pandas.read_csv(filename,header=None)
dfList.append(df)
concatDf=pandas.concat(dfList,axis=0)
concatDf.columns=colnames
y=str(input("What do you want to name your file?"))
concatDf.csv_path = y
concatDf.to_csv(outfile,index=None)
def main():
indir = str(input("What is the directory that you want to concatenate?"))
outfile = str(input("What is the directory that you want to export the merged file to?"))
string_input = input("What are the column names?: ")
input_list = string_input.split()
colnames = [str(x) for x in input_list]
concatenate(indir, outfile, colnames)
그러나 프로그램을 테스트 할 때 약간의 오류가 있습니다. 다음은 나의 의견입니다.
main()
What is the directory that you want to concatenate?/Users/hem/Desktop/Complete_Pilot_Copy/5555_1/DelayDiscounting
What is the directory that you want to export the merged file to?/Users/hem/Desktop/DelayedDiscountingAnalyzed
What are the column names?: Date SubjectID SessionID ProtocolID SiteID TaskID UserResponse LogDiscountRate LogDiscountRateStd QuestionRule NegativeDiscountFlag ZeroDiscountFlag BozoDiscountFlag gldomain ProposedValue1 ProposedDelay1 ProposedValue2 ProposedDelay2 ProposedValue3 ProposedDelay3 TrialStartTimeSec ResponseTimeSec
DDT_5555_1_HUBS071501_BU_062016_135920.csv
DDT_5555_1_HUBS071501_BU_062016_140010.csv
DDT_5555_1_HUBS071501_BU_062016_140051.csv
DelayedDiscounting_5555_1.csv
What do you want to name your file?5555_1DelayDiscounting
Traceback (most recent call last):
File "<ipython-input-2-58ca95c5b364>", line 1, in <module>
main()
File "<ipython-input-1-867fad0a7568>", line 26, in main
concatenate(indir, outfile, colnames)
File "<ipython-input-1-867fad0a7568>", line 17, in concatenate
concatDf.to_csv(outfile,index=None)
File "/Users/hem/anaconda/lib/python3.5/site-packages/pandas/core/frame.py", line 1344, in to_csv
formatter.save()
File "/Users/hem/anaconda/lib/python3.5/site-packages/pandas/formats/format.py", line 1526, in save
compression=self.compression)
File "/Users/hem/anaconda/lib/python3.5/site-packages/pandas/io/common.py", line 424, in _get_handle
f = open(path, mode, errors='replace')
IsADirectoryError: [Errno 21] Is a directory: '/Users/hem/Desktop/DelayedDiscountingAnalyzed'
어떻게 수정하나요? 나는 그것이 내가 전화 번호부에 들어 왔던 방법일지도 모른다라고 생각한다? 감사합니다
O를. 따라서 os, path.join을 수행하여 파일 경로로 만들 수 있습니다. 정말 고마워! –