behavior_development / excel_function.py
Cardanoian's picture
Upload 3 files
d0737e1 verified
import pandas as pd
import os
import tempfile
from api_function import request_one_std
from supabase_function import insert_db
def process_file(file):
df = pd.read_excel(file, engine="openpyxl")
df.dropna(axis=0, inplace=True)
df.set_index(keys="번호", drop=True, inplace=True)
result_dict = {"번호": [], "행발": []}
for i in df.index:
result = request_one_std(df.특성.loc[i])
result_dict["번호"].append(i)
result_dict["행발"].append(result)
result_df = pd.DataFrame(result_dict)
result_df.set_index(keys="번호", drop=True, inplace=True)
# DataFrame을 xlsx 파일로 저장
output_file = os.path.join(tempfile.gettempdir(), "행발결과.xlsx")
print(f"\n\n\n{output_file}")
result_df.to_excel(output_file, index=True)
spe = df.특성.iloc[0] if len(df.특성.iloc[0]) < 30 else df.특성.iloc[0][:30]
insert_db("xlsx", spe, len(result_dict.keys()))
return output_file, "\n".join(
[f"{i}: {result_df.행발.loc[i]}" for i in result_df.index]
)