파이스크립트에서 판다스(Pandas)로 CSV 읽기
import pandas as pd
from pyodide.http import open_url
# URL 에서 csv 데이터를 읽어 판다스 배열(데이터 프레임)으로 변환합니다.
df = pd.read_csv(open_url("http://dreamplan7.cafe24.com/pyscript/BigBasket_Products_200.csv"))
# 평점을 추출대상으로 브랜드별로 그룹화
df_group = df.fillna(0).groupby('brand')[['rating']].mean().sort_values(by='rating', ascending=False)
#df_group.columns = ['brand', 'rating']
# 모든 행을 출력하도록 옵션을 설정합니다.
pd.set_option('display.max_rows', None)
# 출력할 HTML 요소를 선택
csv = Element('csv')
# 산출된 평점의 평균울 출력
csv.write(df_group)
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 7})
fig = plt.figure(figsize=(5, 20))
plt.plot(
df_group['rating'].to_list(),
df_group.index.to_list(),
label='Rating of Brand' )
plt.gca().invert_yaxis()
pltdiv = Element('pltdiv')
pltdiv.write(fig)