Showing
1 changed file
with
47 additions
and
0 deletions
MergeDictionary.py
0 → 100644
1 | +import warnings | ||
2 | + | ||
3 | +warnings.simplefilter(("ignore")) | ||
4 | +import openpyxl | ||
5 | +import pandas as pd | ||
6 | + | ||
7 | +# 000_KNU_New_Vdic2.xlsx 파일 넣기 | ||
8 | + | ||
9 | +Stockfilefolder = input("종목시세폴더입력: ") | ||
10 | +Stockfilename = input("시세파일이름입력:") | ||
11 | +fileStock = "C:/Users/yangj/PycharmProjects/pythonProject1/뉴스키워드/" + Stockfilefolder + "/" + Stockfilename + ".xlsx" | ||
12 | +Stockfile = openpyxl.load_workbook(fileStock) # 파일이름입력 | ||
13 | +stock_ws = Stockfile.active | ||
14 | +Stock_data = [] # list 타입 | ||
15 | +i = 0 | ||
16 | +for row in stock_ws.rows: | ||
17 | + Stock_data.append([]) | ||
18 | + for cell in row: | ||
19 | + if cell.value != None: | ||
20 | + Stock_data[i].append(cell.value) | ||
21 | + i += 1 | ||
22 | +del Stock_data[0] | ||
23 | +for i in range(len(Stock_data)): | ||
24 | + del Stock_data[i][0] | ||
25 | +#print(Stock_data) | ||
26 | + | ||
27 | + | ||
28 | +vert_p = [] # 수직 중복 삭제 | ||
29 | +for i in range(len(Stock_data)): | ||
30 | + vert_p.append([]) | ||
31 | + for j in range(len(Stock_data[i])): | ||
32 | + vert_p[i].append(Stock_data[i][j]) # 단어만 넣기 | ||
33 | +print(vert_p) | ||
34 | + | ||
35 | +vert_p.sort(key=lambda x: x[0]) # 단어 기준으로 정렬 | ||
36 | +for i in range(len(vert_p) - 2): # 단어 비교해서 같으면 누적, 다르면 값 바꾸기 | ||
37 | + for j in range(i + 1, len(vert_p)): | ||
38 | + if vert_p[i][0] == vert_p[j][0] : | ||
39 | + vert_p[i][1] += vert_p[j][1] | ||
40 | + vert_p[j] = ['0', 0] | ||
41 | + if str.isalnum(vert_p[i][0]) == False: | ||
42 | + vert_p[i] =['0', 0] | ||
43 | + | ||
44 | +vert_p = [i for i in vert_p if not '0' in i] # '0'들어간 열 제거 | ||
45 | +df_ver = pd.DataFrame(vert_p) | ||
46 | +df_ver.to_excel(Stockfilename + ' Stock_dictionary2.xlsx', sheet_name='sheet1') | ||
47 | +####사전 완성#### |
-
Please register or login to post a comment