대한민국 SNS 이용현황 블로그 글에 표시된 그림을 좀 다르게 그려보자
%matplotlib inline
import pandas as pd
!cat korean_social_networks.csv
service,mau,10s,20s,30s,40s,50s Kakao Story,24027461,0.1362,0.1577,0.246,0.2366,0.2236 Band,19291737,0.125,0.1311,0.2088,0.2792,0.2559 Facebook,14527484,0.2211,0.2984,0.196,0.1478,0.1367 Instagram,4401436,0.2665,0.3963,0.2201,0.0692,0.048 Twitter,1996014,0.3014,0.1778,0.1839,0.15,0.1869 Vingle,1580701,0.0885,0.4378,0.245,0.1534,0.0753 Cyworld,1114847,0.0795,0.315,0.4091,0.1321,0.0643 Between,828814,0.1373,0.5629,0.2387,0.0389,0.021 Style share,454847,0.6635,0.2556,0.0484,0.0268,0.0057 Tumblr,290681,0.2864,0.2468,0.2378,0.1609,0.0681 Pinterest,238971,0.1232,0.2595,0.1454,0.2956,0.1763
data = pd.read_csv("korean_social_networks.csv", index_col=0)
data
mau | 10s | 20s | 30s | 40s | 50s | |
---|---|---|---|---|---|---|
service | ||||||
Kakao Story | 24027461 | 0.1362 | 0.1577 | 0.2460 | 0.2366 | 0.2236 |
Band | 19291737 | 0.1250 | 0.1311 | 0.2088 | 0.2792 | 0.2559 |
14527484 | 0.2211 | 0.2984 | 0.1960 | 0.1478 | 0.1367 | |
4401436 | 0.2665 | 0.3963 | 0.2201 | 0.0692 | 0.0480 | |
1996014 | 0.3014 | 0.1778 | 0.1839 | 0.1500 | 0.1869 | |
Vingle | 1580701 | 0.0885 | 0.4378 | 0.2450 | 0.1534 | 0.0753 |
Cyworld | 1114847 | 0.0795 | 0.3150 | 0.4091 | 0.1321 | 0.0643 |
Between | 828814 | 0.1373 | 0.5629 | 0.2387 | 0.0389 | 0.0210 |
Style share | 454847 | 0.6635 | 0.2556 | 0.0484 | 0.0268 | 0.0057 |
Tumblr | 290681 | 0.2864 | 0.2468 | 0.2378 | 0.1609 | 0.0681 |
238971 | 0.1232 | 0.2595 | 0.1454 | 0.2956 | 0.1763 |
columns = ['10s', '20s', '30s', '40s', '50s']
def calculate_real(row):
return pd.Series([int(row[col] * row['mau']) for col in target_columns], index=columns)
data[columns] = data.apply(calculate_real, axis=1)
data
mau | 10s | 20s | 30s | 40s | 50s | |
---|---|---|---|---|---|---|
service | ||||||
Kakao Story | 24027461 | 3272540 | 3789130 | 5910755 | 5684897 | 5372540 |
Band | 19291737 | 2411467 | 2529146 | 4028114 | 5386252 | 4936755 |
14527484 | 3212026 | 4335001 | 2847386 | 2147162 | 1985907 | |
4401436 | 1172982 | 1744289 | 968756 | 304579 | 211268 | |
1996014 | 601598 | 354891 | 367066 | 299402 | 373055 | |
Vingle | 1580701 | 139892 | 692030 | 387271 | 242479 | 119026 |
Cyworld | 1114847 | 88630 | 351176 | 456083 | 147271 | 71684 |
Between | 828814 | 113796 | 466539 | 197837 | 32240 | 17405 |
Style share | 454847 | 301790 | 116258 | 22014 | 12189 | 2592 |
Tumblr | 290681 | 83251 | 71740 | 69123 | 46770 | 19795 |
238971 | 29441 | 62012 | 34746 | 70639 | 42130 |
data[columns].plot(kind="barh", stacked=True, figsize=(8,4), title="By services")
<matplotlib.axes._subplots.AxesSubplot at 0x10c50dc88>
data[columns].T.plot(kind="barh", stacked=True, figsize=(8, 4),
title="By ages").legend(loc='center right', bbox_to_anchor=(1.3,0.5))
<matplotlib.legend.Legend at 0x10c77f4e0>