Spaces:
Sleeping
Sleeping
File size: 1,503 Bytes
be7a474 3b1dcc0 be7a474 3b1dcc0 be7a474 49fbc47 be7a474 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
def extract_keywords(file):
# 엑셀 파일 읽기 (첫 번째 행을 무시)
df = pd.read_excel(file, header=None, engine='openpyxl') # header=None으로 열 이름 없이 로드
# 상품명 열을 직접 추출 (필요한 열 번호를 사용)
product_names = df[3][3:] # D4 셀부터 시작하는 데이터를 추출
keywords = []
for name in product_names:
if pd.notna(name): # NaN 값 체크
words = name.split(" ") # 공백 기준으로 단어 분리
keywords.extend(words)
# 키워드 빈도수 계산
keyword_count = Counter(keywords)
# 데이터프레임으로 변환
result_df = pd.DataFrame(keyword_count.items(), columns=['키워드', '빈도수'])
# 빈도수 기준으로 내림차순 정렬
result_df = result_df.sort_values(by='빈도수', ascending=False).reset_index(drop=True)
# 새로운 엑셀 파일 생성 및 이미지 삽입
output_path = "/mnt/data/키워드_분석_결과_with_logo.xlsx"
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
result_df.to_excel(writer, index=False)
workbook = writer.book
worksheet = workbook.active
# 이미지 파일 불러오기
logo_path = "/path/to/ssboost-logo.png" # ssboost-logo.png 경로
img = Image(logo_path)
# A1 셀에 이미지 삽입
worksheet.add_image(img, "A1")
return result_df, output_path
|