2016-12-09 4 views
1

목록에서 요소를 찾을 : -파이썬 팬더 내가 팬더 dataframe에서 두 개의 목록을 만들어

목록 1 : 아래와 같이 ... 폴더 내에서 여러 CSV 파일에서 생성 된

import glob as gb 
 
csv_files = gb.glob("csv\\*.csv") 
 

 
# csv_files = csv_files[0:] 
 

 
# Create list of the CSV in dataframes 
 
dfList = [] 
 
for file in csv_files: 
 
    df_csv = pd.read_csv(file, header=None) 
 
    dfList.append(df_csv)  
 

 
# print (dfList) 
 

 
# Convert each dataframe within the list into individual list 
 
new_dfList = [] 
 
for ind_df in dfList: 
 
    # Convert the dataframe to a list 
 
    new_convert = ind_df.values.tolist() 
 
    new_dfList.append(new_convert)

목록 2은 : 아래와 같이 키워드가 포함 된 텍스트 파일에서 작성되었습니다. 리스트 2에서

# Open keywords TEXT file 
 
keywords = pd.read_csv("words.txt", header=None) 
 

 
# Convert the dataframe to a list 
 
keywords = keywords.values.tolist() 
 

 
# Move out from inner list 
 
# keywords = list(chain(*keywords)) 
 

 
# print (keywords) 
 
keywords[0]

이 키워드는 목록 1에 각 목록과 비교한다. 어떻게해야합니까?

첫 번째 키워드는 (list1) goto 첫 번째 목록 (list1), 두 번째 키워드 (list2) goto 두 번째 목록 (list1), 세 번째 키워드 (list2) goto 세 번째 목록 (list1) .... 등 검색 결과를 반환하고?

답변

0

왜 팬더에서 해보지 않으시겠습니까?

keywords = pd.read_csv("words.txt", header=None) 

dfList = [] 
for file in csv_files: 
    df_csv = pd.read_csv(file, header=None) 
    dfList.append(df_csv) 

df = pd.concat(dfList, keys=keywords) 
# Or, make a panel 
wp = pd.Panel(dict(zip(keywords, dfList))) 
# Or, just leave it as a dictionary 
df_dict = dict(zip(keywords, dfList)) 

그리고 당신이 정말로 목록의 사전하려는 경우 :

df_dict_list = dict(zip(keywords, [df.tolist() for df in dfList]))