def createElementDiv(name):
element = document.createElement('div')
element.id = name
document.body.append(element)
return Element(name)
import pandas as pd
from pyodide.http import open_url
# 판다스에서 csv 를 데이터 프레임으로 읽어옴
df = pd.read_csv(open_url("http://dreamplan7.cafe24.com/pyscript/csv/avocado.csv"))
df.insert(2, 'month', df['Date'].str[:7], True)
df.insert(5, 'Volume2',
df['Total Volume']/10000,
True)
createElementDiv('output1').write(df)
# 월별 매출량 조사
df_group = df.fillna(0) \
.groupby('month')[['Volume2']] \
.sum() \
.sort_values(
by='month',
ascending=True
)
createElementDiv('output1').write(df_group)
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
NanumMyengjo = fm.FontProperties(fname='./NANUMMYEONGJO.TTF')
NanumMyengjoBold = fm.FontProperties(fname='./NANUMMYEONGJOBOLD.TTF')
fig = plt.figure(figsize=(15, 10))
plt.title('월별 아보카도 매출량', fontproperties=NanumMyengjoBold, fontsize=32);
plt.xticks(rotation=45)
plt.bar(
df_group.index.to_list(),
df_group['Volume2'].to_list()
)
plt.xlabel('연도/월', fontproperties=NanumMyengjo, fontsize=16)
plt.ylabel('매출량(단위:만)', fontproperties=NanumMyengjo, fontsize=16)
plt.grid()
fig