Toggle navigation
Toggle navigation
This project
Loading...
Sign in
양지수
/
HCG_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
양지수
2021-05-18 20:47:43 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
baf31ac8e922a664aee591e0ef72ec6772a1fad5
baf31ac8
1 parent
93b38e59
날짜 중복 없애기 성공
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
12 deletions
KNU_edit.py → knu/KnuSentiLex/KNU_edit.py
종목별시세/hmm/hmm1월시세.xlsx
KNU_edit.py
→
knu/KnuSentiLex/
KNU_edit.py
View file @
baf31ac
...
...
@@ -19,6 +19,8 @@ import warnings
warnings
.
simplefilter
((
"ignore"
))
import
openpyxl
import
pandas
as
pd
import
re
from
datetime
import
datetime
class
KnuSL
():
...
...
@@ -48,34 +50,123 @@ if __name__ == "__main__":
print
(
"종료하시려면 #을 입력해주세요!!!"
)
print
(
"-2:매우 부정, -1:부정, 0:중립 or Unkwon, 1:긍정, 2:매우 긍정"
)
print
(
"
\n
"
)
filefolder
=
input
(
"종목폴더입력: "
)
filename
=
input
(
"파일이름입력:"
)
filepos
=
"C:/Users/yangj/PycharmProjects/pythonProject1/뉴스키워드/"
+
filefolder
+
"/"
+
filename
+
".xlsx"
kfile
=
openpyxl
.
load_workbook
(
filepos
)
#파일이름입력
ws
=
k
file
.
active
#########
News
filefolder
=
input
(
"종목폴더입력: "
)
News
filename
=
input
(
"파일이름입력:"
)
Newsfilepos
=
"C:/Users/yangj/PycharmProjects/pythonProject1/뉴스키워드/"
+
Newsfilefolder
+
"/"
+
News
filename
+
".xlsx"
Newsfile
=
openpyxl
.
load_workbook
(
News
filepos
)
#파일이름입력
ws
=
News
file
.
active
data
=
[]
date
=
[]
i
=
0
for
row
in
ws
.
rows
:
data
.
append
([])
date
.
append
(
row
[
1
]
.
value
)
for
cell
in
row
:
if
cell
.
value
!=
None
:
data
[
i
]
.
append
(
cell
.
value
)
i
+=
1
print
(
type
(
data
))
del
data
[
0
]
#첫번째 의미없는 열 삭제
del
date
[
0
]
for
i
in
range
(
len
(
data
)):
del
data
[
i
][
0
]
#각 열의 첫번째 행 삭제
print
(
data
)
for
i
in
range
(
len
(
data
)):
del
data
[
i
][
0
]
#각 열의 날짜 행 삭제
KNUdata
=
[]
Tdata
=
[]
for
x
in
range
(
len
(
data
)):
KNUdata
.
append
([])
Tdata
.
append
([])
for
y
in
range
(
len
(
data
[
x
])):
KNUdata
[
x
]
.
append
(
ksl
.
data_list
(
data
[
x
][
y
]))
Tdata
[
x
]
.
append
([
data
[
x
][
y
],
KNUdata
[
x
][
y
]])
result
=
{
'날짜'
:
date
,
'단어, 극성'
:
Tdata
}
df
=
pd
.
DataFrame
(
result
)
#print(df)
list_df
=
df
.
values
.
tolist
()
#dataframe list로 변경
#print(list_df)
#print(list_df[0][0]) 날짜 2021.01.01.
new_date
=
[]
# 날짜 중복 삭제
for
v
in
date
:
if
v
not
in
new_date
:
new_date
.
append
(
v
)
#print(new_date)
Setlist
=
[]
# 날짜별 키워드 넣기
for
v
in
range
(
len
(
new_date
)):
Setlist
.
append
([])
Setlist
[
v
]
.
append
(
new_date
[
v
])
for
i
in
range
(
len
(
list_df
)):
for
j
in
range
(
len
(
list_df
[
i
][
1
])):
if
new_date
[
v
]
==
list_df
[
i
][
0
]:
Setlist
[
v
]
.
append
(
list_df
[
i
][
1
][
j
])
print
(
Setlist
)
#print(list_df[0][1][0]) 키워드와 극성 ['HMM…"체질개선해', 'X']
#print(list_df[0][1][0][1]) 극성 x
#print(list_df[0][0].split('.')[:3]) ['2021', '01', '01']
#df.to_excel(Newsfilename+' KNU.xlsx',sheet_name='sheet1')
Stockfilefolder
=
input
(
"종목시세폴더입력: "
)
Stockfilename
=
input
(
"시세파일이름입력:"
)
fileStock
=
"C:/Users/yangj/PycharmProjects/pythonProject1/종목별시세/"
+
Stockfilefolder
+
"/"
+
Stockfilename
+
".xlsx"
Stockfile
=
openpyxl
.
load_workbook
(
fileStock
)
#파일이름입력
stock_ws
=
Stockfile
.
active
Stock_data
=
[]
#list 타입
i
=
0
for
row
in
stock_ws
.
rows
:
Stock_data
.
append
([])
for
cell
in
row
:
if
cell
.
value
!=
None
:
Stock_data
[
i
]
.
append
(
cell
.
value
)
i
+=
1
del
Stock_data
[
0
]
for
i
in
range
(
len
(
Stock_data
)):
del
Stock_data
[
i
][
2
]
# 대비 삭제
for
i
in
range
(
len
(
Stock_data
)):
del
Stock_data
[
i
][
7
]
#거래대금 삭제
for
i
in
range
(
len
(
Stock_data
)):
del
Stock_data
[
i
][
7
]
#시가 총액 삭제
for
i
in
range
(
len
(
Stock_data
)):
del
Stock_data
[
i
][
7
]
#상장주식 수 삭제 / 결과:'일자', '종가', '등락률', '시가', '고가', '저가', '거래량'
print
(
Stock_data
)
def
Calpercentage
(
a
,
b
):
return
abs
(
a
-
b
)
/
a
*
100
'''
if(list_df[0][0].split('.')[:3]) == Stock_data[1][0].split('/'): # 날짜 비교
if Calpercentage(Stock_data[1][3],Stock_data[1][4]) > 2 : #당일 시가 대비 고가가 2퍼 높을때
for j in range(len(list_df[0][0])):
if list_df[0][1][j][1] == 'X':
list_df[0][1][j][1]= 1
else:
list_df[0][1][j][1]+=1
elif Calpercentage(Stock_data[1][3],Stock_data[1][5])< -2 : #당일 시가 대비 저가가 2퍼 낮을 때
for j in range(len(list_df[0][0])):
if list_df[0][1][j][1] == 'X':
list_df[0][1][j][1]= -1
else:
list_df[0][1][j][1]-=1
else:
if Stock_data[2][2]>0: # 다음날 주가 등락률이 양수면
for j in range(len(list_df[0][0])): #어제뉴스는 호재 취급
if list_df[0][1][j][1] == 'X':
list_df[0][1][j][1] = 1
else:
list_df[0][1][j][1] += 1
else :
for j in range(len(list_df[0][0])): # 음수면 어제 뉴스는 악재 취급
if list_df[0][1][j][1] == 'X':
list_df[0][1][j][1] = -1
else:
list_df[0][1][j][1] -= 1
else:
while(
'''
df_list
=
pd
.
DataFrame
(
data
)
df_knu
=
pd
.
DataFrame
(
KNUdata
)
result
=
pd
.
concat
([
df_list
,
df_knu
],
axis
=
1
)
#TfIf dataframe으로 변환
result
.
to_excel
(
filename
+
' KNU'
+
'.xlsx'
)
...
...
종목별시세/hmm/hmm1월시세.xlsx
0 → 100644
View file @
baf31ac
No preview for this file type
Please
register
or
login
to post a comment