kijeoung commited on
Commit
4b73621
Β·
verified Β·
1 Parent(s): 1110eae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -24
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  import pandas as pd
3
  from datetime import datetime
4
  import logging
5
- import matplotlib.pyplot as plt
6
 
7
  # 둜그 μ„€μ •
8
  logging.basicConfig(level=logging.INFO)
@@ -30,31 +29,17 @@ def analyze_reviews(file_path):
30
  df_recent = df[df['λ¦¬λ·°λ‚ μ§œ'].dt.year >= start_year]
31
  logger.info("졜근 3λ…„ 데이터 필터링 μ™„λ£Œ")
32
 
33
- # 월별 리뷰 건수 계산
34
- logger.info("월별 리뷰 건수 집계 μ‹œμž‘")
35
- df_recent['λ…„μ›”'] = df_recent['λ¦¬λ·°λ‚ μ§œ'].dt.to_period('M').astype(str)
36
- monthly_review_counts = df_recent.groupby('λ…„μ›”').size().reset_index(name='리뷰건수')
37
- logger.info("월별 리뷰 건수 집계 μ™„λ£Œ")
38
 
39
- # κ·Έλž˜ν”„ 생성
40
- logger.info("κ·Έλž˜ν”„ 생성 μ‹œμž‘")
41
- plt.figure(figsize=(10, 6))
42
- plt.bar(monthly_review_counts['λ…„μ›”'], monthly_review_counts['리뷰건수'], color='skyblue')
43
- plt.xlabel('λ…„μ›”')
44
- plt.ylabel('리뷰 건수')
45
- plt.title('졜근 3λ…„ 월별 리뷰 건수')
46
- plt.xticks(rotation=45)
47
- graph_path = file_path.replace('.xlsx', '_graph.png')
48
- plt.tight_layout()
49
- plt.savefig(graph_path)
50
- plt.close()
51
- logger.info("κ·Έλž˜ν”„ 생성 μ™„λ£Œ")
52
-
53
- # μƒˆλ‘œμš΄ μ‹œνŠΈμ™€ κ·Έλž˜ν”„ μ €μž₯
54
- logger.info("μƒˆλ‘œμš΄ μ‹œνŠΈ 생성 μ‹œμž‘")
55
  with pd.ExcelWriter(file_path, engine='openpyxl', mode='a') as writer:
56
- monthly_review_counts.to_excel(writer, sheet_name='μ›”λ³„κ·Έλž˜ν”„', index=False)
57
- logger.info("μƒˆλ‘œμš΄ μ‹œνŠΈ 생성 μ™„λ£Œ")
58
 
59
  return file_path
60
  except Exception as e:
 
2
  import pandas as pd
3
  from datetime import datetime
4
  import logging
 
5
 
6
  # 둜그 μ„€μ •
7
  logging.basicConfig(level=logging.INFO)
 
29
  df_recent = df[df['λ¦¬λ·°λ‚ μ§œ'].dt.year >= start_year]
30
  logger.info("졜근 3λ…„ 데이터 필터링 μ™„λ£Œ")
31
 
32
+ # 년도별 리뷰 건수 ν•©μ‚° 계산
33
+ logger.info("년도별 리뷰 건수 집계 μ‹œμž‘")
34
+ df_recent['년도'] = df_recent['λ¦¬λ·°λ‚ μ§œ'].dt.year
35
+ yearly_review_counts = df_recent.groupby('년도').size().reset_index(name='리뷰건수')
36
+ logger.info("년도별 리뷰 건수 집계 μ™„λ£Œ")
37
 
38
+ # μƒˆλ‘œμš΄ μ‹œνŠΈμ— μ €μž₯
39
+ logger.info("μƒˆλ‘œμš΄ μ‹œνŠΈμ— 데이터 μ €μž₯ μ‹œμž‘")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  with pd.ExcelWriter(file_path, engine='openpyxl', mode='a') as writer:
41
+ yearly_review_counts.to_excel(writer, sheet_name='년도별 리뷰건수', index=False)
42
+ logger.info("μƒˆλ‘œμš΄ μ‹œνŠΈμ— 데이터 μ €μž₯ μ™„λ£Œ")
43
 
44
  return file_path
45
  except Exception as e: