특정 열의 값에 따라 다른 파일에 쓰고 싶은 커다란 데이터 프레임이 있습니다.병렬 처리 여러 csv 파일에 대한 사전 쓰기
첫 번째 함수는 키가 쓸 파일이고 값이 원래 데이터 프레임의 하위 집합 인 numpy 배열 인 사전을 사용합니다.
def write_in_parallel(inputDict):
for key,value in inputDict.items():
df = pd.DataFrame(value)
with open(baseDir + outDir + outputFileName + key + outputFileType, 'a') as oFile:
data.to_csv(oFile, sep = '|', index = False, header = False)
print("Finished writing month: " + outputFileName + key)
함수 2는 데이터 프레임과 데이터 프레임 자체를 분할하기 위해 열 값을 취하여 데이터 프레임을 반환합니다.
def make_slices(files, df):
outlist = dict()
for item in files:
data = np.array(df[df.iloc[:,1] == item])
outlist[item] = data
return outlist
최종 함수는 희망 병렬 make_slices
에서 사전 위에 write_in_parallel
반복하는 멀티 전화를 이용한다.
def make_dynamic_columns():
perfPath = baseDir + rawDir
perfFiles = glob.glob(perfPath + "/*" + inputFileType)
perfFrame = pd.DataFrame()
for file_ in perfFiles:
df = pd.read_table(file_, delimiter = '|', header = None)
df.fillna(missingDataChar,inplace=True)
df.iloc[:,1] = df.iloc[:,1].astype(str)
fileList = list(df.iloc[:, 1].astype('str').unique())
with mp.Pool(processes=10) as pool:
pool.map(write_in_parallel, make_slices(fileList, df))
나는 점점 오전 오류는 pool.map를 믿고 날 리드하고 write_in_parallel
이 사전을받지 않는 'str을 객체에는 속성 항목이 없습니다'입니다. 이 문제를 해결하는 방법을 모르겠습니다. 어떤 도움이라도 대단히 감사합니다.
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/home/ssun/library/python/Python-3.5.2/build/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/home/ssun/library/python/Python-3.5.2/build/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "_FHLMC_LLP_dataprep.py", line 22, in write_in_parallel
for key,value in dict.items():
AttributeError: 'str' object has no attribute 'items'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "_FHLMC_LLP_dataprep.py", line 59, in <module>
make_dynamic_columns_freddie()
File "_FHLMC_LLP_dataprep.py", line 55, in make_dynamic_columns_freddie
pool.map(write_in_parallel, dictinput)
File "/home/ssun/library/python/Python-3.5.2/build/lib/python3.5/multiprocessing/pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/home/ssun/library/python/Python-3.5.2/build/lib/python3.5/multiprocessing/pool.py", line 608, in get
raise self._value
AttributeError: 'str' object has no attribute 'items'
전체 스택 추적을 게시하십시오. – FHTMitchell
추적을 추가하십시오. –