df = pd.read_csv('./data/101_DT_1KE10081_20231106160107.csv', encoding='cp949')
df.rename(columns={'지역별':'국가(대륙)별'}, inplace=True)
df = df.drop(['항목', '단위', 'Unnamed: 29'], axis=1)
df_new = df.melt(id_vars=['국가(대륙)별', '상품군별', '판매유형별'], var_name='기간', value_name='백만원')
df_new['연도'] = df_new['기간'].map(lambda x: int(x.split('.')[0]))
df_new['분기'] = df_new['기간'].map(lambda x: int(str(x.split('.')[1]).split('/')[0]))
df_new['백만원'] = df_new['백만원'].replace('-', pd.np.nan).astype(dtype='float64')
df_new.replace({np.nan:0}, inplace=True)
df_new = df_new[(df_new['국가(대륙)별'] != '합계') & (df_new['상품군별'] != '합계')].copy()
df_new.isnull().sum()
전체 상품군별 시각화
sns.lineplot(data=df_total, x='연도', y='백만원')
plt.show()
sns.lineplot(data=df_total, x='연도', y='백만원', hue='상품군별')
plt.legend(title="상품군별", bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()
sns.relplot(data=df_total, x="연도", y="백만원", hue="상품군별", kind="line", col="상품군별", col_wrap=4)
df_sub = df_total[~df_total.isin({'상품군별':['화장품', '의류 및 패션 관련 상품']})]
sns.relplot(data=df_sub, x='연도', y='백만원', hue='상품군별', kind='line', col_wrap=4, col='상품군별')
화장품 해외 판매액 시각화
df_cosmetic = df_total[df_total['상품군별'] == '화장품']
plt.figure(figsize=(12,6))
sns.lineplot(data=df_cosmetic, x='연도', y='백만원', hue='분기')
plt.figure(figsize=(12,6))
plt.xticks(rotation=30)
sns.lineplot(data=df_cosmetic, x='기간', y='백만원')
plt.figure(figsize=(15,9))
plt.xticks(rotation=30)
sns.lineplot(data=df_cosmetic, x='기간', y='백만원', hue='국가(대륙)별')
df_cosmetic_sub = df_cosmetic[df_cosmetic['국가(대륙)별'] != '중국']
plt.figure(figsize=(15,9))
plt.xticks(rotation=30)
sns.lineplot(data=df_cosmetic_sub, x='기간', y='백만원', hue='국가(대륙)별')
패션 의류 온라인 해외 직접 판매액 시각화
df_fashion = df_new[(df_new['상품군별'] == '의류 및 패션 관련 상품') & (df_new['판매유형별'] == '계')]
plt.figure(figsize=(20, 8))
plt.xticks(rotation=30)
sns.lineplot(data=df_fashion, x="기간", y="백만원", hue="국가(대륙)별")
df_fashion = df_fashion[df_fashion['국가(대륙)별'].isin(['기타','대양주','미국','아세안','유럽연합','유럽연합+영국','일본','중국','중동'])]
result = df_fashion1.pivot_table(index="국가(대륙)별", columns="연도", values="백만원", aggfunc="sum")
plt.figure(figsize=(10, 6))
sns.heatmap(result, cmap="Blues", annot=True, fmt=".0f")