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