LLMpromt1111 / app.py
aliceblue11's picture
Update app.py
065fc33 verified
raw
history blame
1.84 kB
import pandas as pd
import os
# 엑셀 파일 경로
file_path = '파일경로.xlsx'
# 파일이 존재하는지 확인하는 코드 추가
if os.path.exists(file_path):
# 파일이 존재하면 엑셀 파일을 읽어들임
df = pd.read_excel(file_path)
# 1. G1셀에 "글자수"를 입력
df.loc[0, 'G'] = "글자수"
# 2. G2셀부터 G열에 D열의 글자수를 입력
df['G'] = df['D'].apply(lambda x: len(str(x)) if pd.notnull(x) else 0)
# 3. G열 기준으로 내림차순 정렬
df = df.sort_values(by='G', ascending=False)
# 4. E열의 데이터가 5, 4점인 항목에서 G열이 500자 이하인 항목 중 10개를 긍정리뷰 10개로 선택
positive_reviews = df[(df['E'].isin([5, 4])) & (df['G'] <= 500)].head(10)
# 5. E열의 데이터가 1, 2점인 항목에서 G열이 500자 이하인 항목 중 10개를 부정리뷰 10개로 선택
negative_reviews = df[(df['E'].isin([1, 2])) & (df['G'] <= 500)].head(10)
# 6. 긍정리뷰, 부정리뷰의 리뷰날짜, 옵션, 리뷰내용을 모두 가져옴
positive_reviews_data = positive_reviews[['리뷰날짜', '옵션', 'D']] # D열이 리뷰내용
negative_reviews_data = negative_reviews[['리뷰날짜', '옵션', 'D']]
# 긍정리뷰 10개 출력
print("긍정리뷰 10개:")
print(positive_reviews_data)
# 부정리뷰 10개 출력
print("부정리뷰 10개:")
print(negative_reviews_data)
# 필요시 결과를 새로운 엑셀 파일로 저장
positive_reviews_data.to_excel('긍정리뷰_10개.xlsx', index=False)
negative_reviews_data.to_excel('부정리뷰_10개.xlsx', index=False)
else:
# 파일이 존재하지 않으면 에러 메시지 출력
print(f"Error: 파일을 찾을 수 없습니다. 경로를 확인해주세요: {file_path}")