Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
kihoon.lee
Lotte-LogicKor
Commits
6fff3169
Commit
6fff3169
authored
Oct 22, 2024
by
Liky98
Browse files
각 task 별 점수를 평균내는 시트 추가
parent
5fc9d92b
Changes
1
Hide whitespace changes
Inline
Side-by-side
merge_results.py
View file @
6fff3169
...
...
@@ -91,6 +91,9 @@ def save_to_excel(score_sheets, output_file):
딕셔너리에 저장된 데이터프레임을 각 시트로 저장하여 엑셀 파일로 저장합니다.
"""
with
pd
.
ExcelWriter
(
output_file
,
engine
=
'openpyxl'
)
as
writer
:
# 새로운 시트를 위한 데이터프레임 초기화
average_scores_df
=
pd
.
DataFrame
()
for
sheet_name
,
df
in
score_sheets
.
items
():
df
.
to_excel
(
writer
,
sheet_name
=
sheet_name
)
...
...
@@ -119,7 +122,40 @@ def save_to_excel(score_sheets, output_file):
# 인덱스 열 너비 조정
max_length
=
max
(
df
.
index
.
astype
(
str
).
map
(
len
).
max
(),
len
(
df
.
index
.
name
)
if
df
.
index
.
name
else
0
)
+
2
worksheet
.
column_dimensions
[
get_column_letter
(
1
)].
width
=
max_length
# 새로운 시트를 위한 평균 계산
if
'Score Average'
in
df
.
columns
:
average_scores_df
[
sheet_name
]
=
df
[
'Score Average'
]
# 모델별 평균 계산 후 새로운 시트에 저장
if
not
average_scores_df
.
empty
:
average_scores_df
[
'Overall Average'
]
=
average_scores_df
.
mean
(
axis
=
1
,
skipna
=
True
)
average_scores_df
.
to_excel
(
writer
,
sheet_name
=
'Model Average Scores'
)
# 스타일 적용
avg_worksheet
=
writer
.
sheets
[
'Model Average Scores'
]
# 헤더 스타일
for
col_num
,
col
in
enumerate
(
average_scores_df
.
columns
,
1
):
cell
=
avg_worksheet
.
cell
(
row
=
1
,
column
=
col_num
+
1
)
cell
.
font
=
header_font
cell
.
alignment
=
Alignment
(
horizontal
=
'center'
,
vertical
=
'center'
)
# 인덱스 스타일
for
row_num
in
range
(
2
,
len
(
average_scores_df
)
+
2
):
cell
=
avg_worksheet
.
cell
(
row
=
row_num
,
column
=
1
)
cell
.
font
=
header_font
cell
.
alignment
=
Alignment
(
horizontal
=
'center'
,
vertical
=
'center'
)
# 열 너비 자동 조정
for
col_num
,
col
in
enumerate
(
average_scores_df
.
columns
,
1
):
max_length
=
max
(
average_scores_df
[
col
].
astype
(
str
).
map
(
len
).
max
(),
len
(
col
))
+
2
avg_worksheet
.
column_dimensions
[
get_column_letter
(
col_num
+
1
)].
width
=
max_length
# 인덱스 열 너비 조정
max_length
=
max
(
average_scores_df
.
index
.
astype
(
str
).
map
(
len
).
max
(),
len
(
average_scores_df
.
index
.
name
)
if
average_scores_df
.
index
.
name
else
0
)
+
2
avg_worksheet
.
column_dimensions
[
get_column_letter
(
1
)].
width
=
max_length
print
(
f
"모든 스코어가 '
{
output_file
}
' 파일에 저장되었습니다."
)
def
main
():
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment