from pathlib import Path
from IPython.display import display
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import scatter_matrix
%matplotlib inline
data_path = Path('.')
year = 2017
calendars = pd.read_table(data_path / 'calendars.tsv', dtype={'likes_count': int, 'subscriber_count': int})
calendars = calendars.drop('year', axis=1)
calendars = calendars.set_index('calendar_id')
calendars[:3]
title | url | category | participants_count | likes_count | subscribers_count | |
---|---|---|---|---|---|---|
calendar_id | ||||||
haskell5 | Haskell (その5) Advent Calendar 2017 | https://qiita.com/advent-calendar/2017/haskell5 | Programming Langs | 5 | 23 | 0 |
vivaldi | Vivaldiブラウザー Advent Calendar 2017 | https://qiita.com/advent-calendar/2017/vivaldi | Web Technologies | 1 | 3 | 0 |
yaruki | やる気 Advent Calendar 2017 | https://qiita.com/advent-calendar/2017/yaruki | Miscellaneous | 1 | 0 | 1 |
likers = pd.read_csv(data_path / 'likers.tsv', sep='\t')
likers = likers.drop('year', axis=1)
likers = likers.set_index('calendar_id')
likers[:3]
date | user_name | user_url | |
---|---|---|---|
calendar_id | |||
haskell5 | 4 | takenobu-hs | https://qiita.com/takenobu-hs |
haskell5 | 4 | makoraru | https://qiita.com/makoraru |
haskell5 | 4 | lotz | https://qiita.com/lotz |
ranking = pd.DataFrame(calendars['category'])
ranking[['subscribers', 'likes']] = calendars[['subscribers_count', 'likes_count']].rank(ascending=False).astype(int)
ranking = ranking.reset_index()
display(ranking.set_index('subscribers').sort_index()[:10])
display(ranking.set_index('likes').sort_index()[:10])
calendar_id | category | likes | |
---|---|---|---|
subscribers | |||
1 | vscode | Editors | 89 |
2 | javascript | Programming Langs | 32 |
2 | chromium | Web Technologies | 102 |
4 | vue | Libraries | 35 |
5 | docker | DevOps | 122 |
6 | slack | Services | 212 |
7 | smart-speaker | IoT | 15 |
8 | vim | Editors | 60 |
9 | go | Programming Langs | 50 |
9 | vue2 | Libraries | 27 |
calendar_id | category | subscribers | |
---|---|---|---|
likes | |||
1 | fromscratch | Company | 134 |
2 | tis | Company | 152 |
3 | crowdworks | Company | 218 |
4 | livesense-gaku | Company | 152 |
5 | ateam-lifestyle | Company | 258 |
6 | musashino | Company | 91 |
7 | ex-mixi | Company | 163 |
8 | mixi | Company | 136 |
9 | litalico | Company | 246 |
10 | increments | Company | 156 |
cals_by_category = pd.DataFrame()
cals_by_category['cals'] = calendars.groupby('category')['title'].count()
cals_by_category[['subs', 'likes']] = calendars.groupby('category')['subscribers_count', 'likes_count'].sum()
cals_by_category['subs/cal'] = (cals_by_category['subs'] / cals_by_category['cals']).astype(int)
cals_by_category['likes/cal'] = (cals_by_category['likes'] / cals_by_category['cals']).astype(int)
cals_by_category['likes/sub'] = cals_by_category['likes'] / cals_by_category['subs']
cals_by_category
cals | subs | likes | subs/cal | likes/cal | likes/sub | |
---|---|---|---|---|---|---|
category | ||||||
Academic | 22 | 3015 | 2284 | 137 | 103 | 0.757546 |
Company | 204 | 5934 | 56898 | 29 | 278 | 9.588473 |
Databases | 9 | 570 | 492 | 63 | 54 | 0.863158 |
DevOps | 19 | 1787 | 670 | 94 | 35 | 0.374930 |
Editors | 10 | 1980 | 1068 | 198 | 106 | 0.539394 |
IoT | 17 | 1795 | 2800 | 105 | 164 | 1.559889 |
Libraries | 61 | 5656 | 7080 | 92 | 116 | 1.251768 |
Miscellaneous | 63 | 2093 | 5255 | 33 | 83 | 2.510750 |
Mobile | 13 | 1452 | 2306 | 111 | 177 | 1.588154 |
OS | 6 | 548 | 379 | 91 | 63 | 0.691606 |
Programming Langs | 89 | 8994 | 10690 | 101 | 120 | 1.188570 |
Services | 40 | 3108 | 2184 | 77 | 54 | 0.702703 |
Web Technologies | 40 | 3691 | 2909 | 92 | 72 | 0.788133 |
cals_by_category.plot.bar(subplots=True, figsize=(4, 10))
array([<matplotlib.axes._subplots.AxesSubplot object at 0x10ae1dbe0>, <matplotlib.axes._subplots.AxesSubplot object at 0x10af55b00>, <matplotlib.axes._subplots.AxesSubplot object at 0x10bccdc88>, <matplotlib.axes._subplots.AxesSubplot object at 0x10bd08c50>, <matplotlib.axes._subplots.AxesSubplot object at 0x10c33f6d8>, <matplotlib.axes._subplots.AxesSubplot object at 0x10c33f710>], dtype=object)
calendars[['likes_count', 'subscribers_count']].corr()
likes_count | subscribers_count | |
---|---|---|
likes_count | 1.000000 | 0.196388 |
subscribers_count | 0.196388 | 1.000000 |
calendars.plot.scatter(figsize=(4, 4), x='subscribers_count', y='likes_count')
<matplotlib.axes._subplots.AxesSubplot at 0x10c538198>
colors = calendars['category'].apply(lambda x: 'red' if x == 'Company' else 'blue')
calendars.plot.scatter(figsize=(4, 4), x='subscribers_count', y='likes_count', color=colors)
<matplotlib.axes._subplots.AxesSubplot at 0x10c718a20>
fig, ax = plt.subplots(1, 2, figsize=(8, 4))
calendars[calendars['category'] == 'Company'].plot.scatter(ax=ax[0], x='subscribers_count', y='likes_count', color='red')
calendars[calendars['category'] != 'Company'].plot.scatter(ax=ax[1], x='subscribers_count', y='likes_count', color='blue')
<matplotlib.axes._subplots.AxesSubplot at 0x10c86c748>
calendars.groupby(calendars['category'] == 'Company')[['likes_count', 'subscribers_count']].corr()
likes_count | subscribers_count | ||
---|---|---|---|
category | |||
False | likes_count | 1.000000 | 0.574489 |
subscribers_count | 0.574489 | 1.000000 | |
True | likes_count | 1.000000 | 0.462269 |
subscribers_count | 0.462269 | 1.000000 |
cals = calendars['category subscribers_count likes_count'.split()].copy()
cals.columns = ['category', 'subs', 'likes']
cals = cals[(cals['likes'] != 0) & (cals['subs'] != 0)]
cals = cals.sort_values(['likes'], ascending=False)[:50]
cals['uu'] = likers.groupby(level=0)['user_name'].unique().apply(len)
cals['likes/sub'] = cals['likes'] / cals['subs']
cals['likes/uu'] = cals['likes'] / cals['uu']
is_company = cals['category'].apply(lambda x: x == 'Company')
colors = cals['category'].apply(lambda x: 'red' if x == 'Company' else 'blue')
display(pd.DataFrame(cals.groupby(calendars['category']).size().rename('calendars')))
display(pd.DataFrame(cals.groupby(is_company).size().rename('calendars')))
display(cals[:50])
calendars | |
---|---|
category | |
Academic | 1 |
Company | 35 |
IoT | 2 |
Libraries | 3 |
Miscellaneous | 2 |
Mobile | 2 |
Programming Langs | 5 |
calendars | |
---|---|
category | |
False | 15 |
True | 35 |
category | subs | likes | uu | likes/sub | likes/uu | |
---|---|---|---|---|---|---|
calendar_id | ||||||
fromscratch | Company | 94 | 3065 | 526 | 32.606383 | 5.826996 |
tis | Company | 80 | 3041 | 2105 | 38.012500 | 1.444656 |
crowdworks | Company | 52 | 2476 | 1765 | 47.615385 | 1.402833 |
livesense-gaku | Company | 80 | 2439 | 1799 | 30.487500 | 1.355753 |
ateam-lifestyle | Company | 43 | 2389 | 1481 | 55.558140 | 1.613099 |
musashino | Company | 133 | 2368 | 1522 | 17.804511 | 1.555848 |
ex-mixi | Company | 76 | 1941 | 1528 | 25.539474 | 1.270288 |
mixi | Company | 91 | 1909 | 1666 | 20.978022 | 1.145858 |
litalico | Company | 45 | 1489 | 1050 | 33.088889 | 1.418095 |
increments | Company | 79 | 1366 | 1070 | 17.291139 | 1.276636 |
livesense-kan | Company | 50 | 1361 | 906 | 27.220000 | 1.502208 |
livesense-ji | Company | 59 | 1353 | 827 | 22.932203 | 1.636034 |
kuso-app2017 | Miscellaneous | 186 | 1307 | 1200 | 7.026882 | 1.089167 |
basicinc | Company | 28 | 1107 | 774 | 39.535714 | 1.430233 |
smart-speaker | IoT | 421 | 1039 | 796 | 2.467933 | 1.305276 |
wacul | Company | 15 | 1030 | 859 | 68.666667 | 1.199069 |
globis | Company | 50 | 965 | 505 | 19.300000 | 1.910891 |
dmm2 | Company | 161 | 934 | 695 | 5.801242 | 1.343885 |
nttcom | Company | 73 | 902 | 646 | 12.356164 | 1.396285 |
axe | Miscellaneous | 62 | 892 | 781 | 14.387097 | 1.142125 |
justsystems | Company | 28 | 796 | 734 | 28.428571 | 1.084469 |
cdatasoftware | Libraries | 16 | 788 | 760 | 49.250000 | 1.036842 |
dwango | Company | 156 | 745 | 601 | 4.775641 | 1.239601 |
m3 | Company | 27 | 739 | 446 | 27.370370 | 1.656951 |
fujitsu | Company | 80 | 728 | 617 | 9.100000 | 1.179903 |
fringe81 | Company | 43 | 704 | 206 | 16.372093 | 3.417476 |
vue2 | Libraries | 395 | 653 | 508 | 1.653165 | 1.285433 |
lifull2 | Company | 31 | 638 | 494 | 20.580645 | 1.291498 |
lifull | Company | 50 | 605 | 461 | 12.100000 | 1.312364 |
ut_ap | Company | 49 | 601 | 573 | 12.265306 | 1.048866 |
math-and-computer | Academic | 385 | 593 | 481 | 1.540260 | 1.232848 |
javascript | Programming Langs | 487 | 589 | 335 | 1.209446 | 1.758209 |
hikkoshi | Company | 31 | 567 | 208 | 18.290323 | 2.725962 |
dwango2 | Company | 110 | 560 | 433 | 5.090909 | 1.293303 |
vue | Libraries | 460 | 554 | 431 | 1.204348 | 1.285383 |
firstserver | Company | 18 | 542 | 286 | 30.111111 | 1.895105 |
retty | Company | 44 | 537 | 365 | 12.204545 | 1.471233 |
firebase | Mobile | 246 | 527 | 393 | 2.142276 | 1.340967 |
okinawarb | Company | 9 | 500 | 484 | 55.555556 | 1.033058 |
toreta | Company | 45 | 485 | 435 | 10.777778 | 1.114943 |
accounting_saas_japan | Company | 16 | 467 | 80 | 29.187500 | 5.837500 |
vasily | Company | 44 | 457 | 215 | 10.386364 | 2.125581 |
webassembly | Programming Langs | 234 | 455 | 345 | 1.944444 | 1.318841 |
rust-lang | Programming Langs | 267 | 444 | 210 | 1.662921 | 2.114286 |
lit-mentor | Company | 45 | 441 | 148 | 9.800000 | 2.979730 |
swift | Programming Langs | 239 | 433 | 279 | 1.811715 | 1.551971 |
ios | Mobile | 198 | 429 | 229 | 2.166667 | 1.873362 |
a-t-brides | Company | 26 | 422 | 157 | 16.230769 | 2.687898 |
iotlt_neo | IoT | 104 | 408 | 331 | 3.923077 | 1.232628 |
go | Programming Langs | 395 | 397 | 278 | 1.005063 | 1.428058 |
cals[:50]['likes/uu'].plot.barh(figsize=(4, 10), color=colors).invert_yaxis()
cals['likes/uu'].plot.hist(figsize=(4, 3), bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x10c859400>
cals[cals['likes/uu'] >= 3]
category | subs | likes | uu | likes/sub | likes/uu | |
---|---|---|---|---|---|---|
calendar_id | ||||||
fromscratch | Company | 94 | 3065 | 526 | 32.606383 | 5.826996 |
fringe81 | Company | 43 | 704 | 206 | 16.372093 | 3.417476 |
accounting_saas_japan | Company | 16 | 467 | 80 | 29.187500 | 5.837500 |
likes_by_date = likers.loc[cals.index].groupby('calendar_id')['date'].value_counts()
likes_by_date = pd.DataFrame(likes_by_date).join(cals[['category', 'likes']])
likes_by_date = likes_by_date.rename(columns={'likes': 'cal_likes', 'date': 'item_likes'})
likes_by_date = likes_by_date.sort_values(['cal_likes', 'item_likes'], ascending=False)
likes_by_date[:3]
item_likes | category | cal_likes | ||
---|---|---|---|---|
calendar_id | date | |||
fromscratch | 6 | 248 | Company | 3065 |
22 | 184 | Company | 3065 | |
23 | 150 | Company | 3065 |
likes_by_date['item_likes'].plot.hist(figsize=(6, 3), logy=False, bins=50)
<matplotlib.axes._subplots.AxesSubplot at 0x10d004ef0>
likes_by_date['item_likes'].plot.hist(figsize=(6, 3), logy=True, bins=50)
<matplotlib.axes._subplots.AxesSubplot at 0x10d07f780>
likes_by_date.groupby('category')['item_likes'].describe()
count | mean | std | min | 25% | 50% | 75% | max | |
---|---|---|---|---|---|---|---|---|
category | ||||||||
Academic | 14.0 | 42.642857 | 55.556772 | 1.0 | 10.0 | 19.0 | 63.75 | 208.0 |
Company | 758.0 | 54.098945 | 131.516465 | 1.0 | 11.0 | 18.0 | 32.75 | 1437.0 |
IoT | 43.0 | 34.627907 | 84.698913 | 3.0 | 6.0 | 12.0 | 22.50 | 497.0 |
Libraries | 52.0 | 39.019231 | 116.758086 | 1.0 | 3.0 | 8.5 | 18.25 | 754.0 |
Miscellaneous | 25.0 | 88.600000 | 237.404718 | 3.0 | 5.0 | 10.0 | 24.00 | 1092.0 |
Mobile | 37.0 | 26.810811 | 40.496802 | 4.0 | 8.0 | 15.0 | 27.00 | 241.0 |
Programming Langs | 87.0 | 24.919540 | 33.193309 | 2.0 | 7.0 | 16.0 | 25.00 | 210.0 |
likes_by_date.groupby(level=0, sort=False)['item_likes'].describe()[:50]
count | mean | std | min | 25% | 50% | 75% | max | |
---|---|---|---|---|---|---|---|---|
calendar_id | ||||||||
fromscratch | 25.0 | 123.560000 | 32.751692 | 95.0 | 104.00 | 112.0 | 131.00 | 248.0 |
tis | 25.0 | 122.160000 | 226.398925 | 14.0 | 22.00 | 35.0 | 63.00 | 870.0 |
crowdworks | 24.0 | 105.875000 | 280.889629 | 22.0 | 25.00 | 28.0 | 47.75 | 1402.0 |
livesense-gaku | 25.0 | 98.880000 | 240.755464 | 6.0 | 20.00 | 26.0 | 35.00 | 901.0 |
ateam-lifestyle | 25.0 | 96.120000 | 145.153459 | 18.0 | 28.00 | 34.0 | 70.00 | 585.0 |
musashino | 22.0 | 107.863636 | 201.179923 | 21.0 | 31.25 | 53.0 | 90.50 | 983.0 |
ex-mixi | 11.0 | 177.272727 | 249.809564 | 9.0 | 21.50 | 30.0 | 211.00 | 785.0 |
mixi | 20.0 | 95.550000 | 316.941880 | 4.0 | 11.75 | 14.0 | 28.00 | 1437.0 |
litalico | 24.0 | 62.250000 | 128.545796 | 13.0 | 17.00 | 19.0 | 25.50 | 573.0 |
increments | 9.0 | 156.777778 | 191.897614 | 2.0 | 25.00 | 52.0 | 276.00 | 509.0 |
livesense-kan | 25.0 | 54.600000 | 105.620389 | 9.0 | 18.00 | 22.0 | 29.00 | 455.0 |
livesense-ji | 25.0 | 54.280000 | 95.060735 | 10.0 | 21.00 | 32.0 | 62.00 | 498.0 |
kuso-app2017 | 16.0 | 82.375000 | 269.519047 | 3.0 | 5.75 | 11.5 | 22.50 | 1092.0 |
basicinc | 24.0 | 46.291667 | 82.673522 | 3.0 | 10.00 | 16.0 | 27.00 | 344.0 |
smart-speaker | 23.0 | 46.913043 | 101.306875 | 6.0 | 12.50 | 19.0 | 31.50 | 497.0 |
wacul | 23.0 | 44.913043 | 106.530795 | 1.0 | 3.50 | 8.0 | 20.00 | 381.0 |
globis | 21.0 | 46.380952 | 57.926226 | 15.0 | 22.00 | 26.0 | 29.00 | 256.0 |
dmm2 | 20.0 | 46.900000 | 103.101840 | 5.0 | 9.25 | 14.0 | 28.00 | 470.0 |
nttcom | 24.0 | 37.750000 | 77.884669 | 4.0 | 8.50 | 18.0 | 32.00 | 391.0 |
axe | 9.0 | 99.666667 | 180.739453 | 3.0 | 3.00 | 8.0 | 51.00 | 503.0 |
justsystems | 25.0 | 34.480000 | 134.730632 | 2.0 | 4.00 | 9.0 | 11.00 | 681.0 |
cdatasoftware | 16.0 | 49.750000 | 187.803621 | 1.0 | 2.00 | 3.0 | 3.25 | 754.0 |
dwango | 18.0 | 41.666667 | 59.978427 | 6.0 | 9.50 | 18.0 | 36.50 | 248.0 |
m3 | 24.0 | 30.916667 | 58.471038 | 9.0 | 11.00 | 15.0 | 23.00 | 300.0 |
fujitsu | 21.0 | 34.714286 | 110.747976 | 2.0 | 4.00 | 9.0 | 18.00 | 517.0 |
fringe81 | 25.0 | 28.200000 | 9.451631 | 17.0 | 22.00 | 25.0 | 29.00 | 58.0 |
vue2 | 18.0 | 37.444444 | 77.196634 | 2.0 | 7.75 | 14.5 | 28.75 | 337.0 |
lifull2 | 25.0 | 25.560000 | 74.079394 | 3.0 | 5.00 | 7.0 | 11.00 | 375.0 |
lifull | 23.0 | 25.652174 | 70.808711 | 3.0 | 6.00 | 9.0 | 15.00 | 349.0 |
ut_ap | 18.0 | 35.222222 | 116.619823 | 1.0 | 5.50 | 7.5 | 8.75 | 502.0 |
math-and-computer | 14.0 | 42.642857 | 55.556772 | 1.0 | 10.00 | 19.0 | 63.75 | 208.0 |
javascript | 20.0 | 22.550000 | 27.169013 | 4.0 | 6.00 | 15.0 | 20.75 | 100.0 |
hikkoshi | 25.0 | 22.720000 | 18.183142 | 9.0 | 15.00 | 18.0 | 23.00 | 103.0 |
dwango2 | 15.0 | 35.733333 | 62.419625 | 1.0 | 9.00 | 11.0 | 20.00 | 240.0 |
vue | 18.0 | 31.055556 | 60.325073 | 2.0 | 7.25 | 11.0 | 31.25 | 265.0 |
firstserver | 24.0 | 22.625000 | 33.732725 | 8.0 | 11.00 | 13.0 | 17.00 | 162.0 |
retty | 25.0 | 21.680000 | 28.988101 | 3.0 | 6.00 | 11.0 | 17.00 | 130.0 |
firebase | 19.0 | 29.421053 | 54.398035 | 4.0 | 9.00 | 12.0 | 19.50 | 241.0 |
okinawarb | 3.0 | 167.333333 | 219.730138 | 8.0 | 42.00 | 76.0 | 247.00 | 418.0 |
toreta | 18.0 | 27.000000 | 89.658174 | 1.0 | 3.25 | 5.0 | 8.00 | 386.0 |
accounting_saas_japan | 25.0 | 18.800000 | 6.474308 | 13.0 | 16.00 | 17.0 | 19.00 | 43.0 |
vasily | 23.0 | 20.000000 | 16.234083 | 7.0 | 11.00 | 13.0 | 19.50 | 67.0 |
webassembly | 14.0 | 32.500000 | 54.023855 | 2.0 | 8.00 | 12.0 | 24.50 | 210.0 |
rust-lang | 19.0 | 22.789474 | 15.820447 | 4.0 | 15.00 | 21.0 | 26.00 | 71.0 |
lit-mentor | 24.0 | 18.416667 | 6.021098 | 5.0 | 15.00 | 18.0 | 23.00 | 32.0 |
swift | 18.0 | 24.555556 | 26.417958 | 2.0 | 5.25 | 14.5 | 37.75 | 98.0 |
ios | 18.0 | 24.055556 | 18.001543 | 6.0 | 9.50 | 17.5 | 30.25 | 65.0 |
a-t-brides | 25.0 | 17.000000 | 14.352700 | 8.0 | 12.00 | 15.0 | 16.00 | 84.0 |
iotlt_neo | 20.0 | 20.500000 | 59.847614 | 3.0 | 4.00 | 5.5 | 10.50 | 274.0 |
go | 16.0 | 24.187500 | 41.153726 | 4.0 | 7.75 | 14.0 | 22.00 | 175.0 |
likes_by_date[likes_by_date['item_likes']>=1000]
item_likes | category | cal_likes | ||
---|---|---|---|---|
calendar_id | date | |||
crowdworks | 16 | 1402 | Company | 2476 |
mixi | 1 | 1437 | Company | 1909 |
kuso-app2017 | 21 | 1092 | Miscellaneous | 1307 |
fig, ax = plt.subplots(10, 5, figsize=(12, 18))
for axes, (calendar_id, df) in zip(ax.flatten(), likes_by_date.groupby(level=0, sort=False)['item_likes']):
df = df.reset_index('calendar_id', drop=True)
ylim = (0, df.describe()['75%'])
color = colors[calendar_id]
df.plot.bar(ax=axes, title=calendar_id, ylim=ylim, color=color).invert_xaxis()
axes.get_xaxis().set_visible(False)
fig, ax = plt.subplots(5, 10, figsize=(12, 12))
for axes, (calendar_id, df) in zip(ax.flatten(), likes_by_date.groupby(level=0, sort=False)['item_likes']):
color = colors[calendar_id]
df.plot.box(ax=axes, title=calendar_id, color=color)
axes.get_xaxis().set_visible(False)
fig, ax = plt.subplots(5, 10, figsize=(12, 12))
for axes, (calendar_id, df) in zip(ax.flatten(), likes_by_date.groupby(level=0, sort=False)['item_likes']):
color = colors[calendar_id]
df.plot.box(ax=axes, title=calendar_id, color=color, ylim=(0, 20), sharey=True)
axes.get_xaxis().set_visible(False)
likes_by_date.groupby(level=0, sort=False)['item_likes'].min()[:50].plot.barh(figsize=(4, 10), color=colors, xlim=(0, 30)).invert_yaxis()
likes_by_user = pd.DataFrame(likers.loc[cals.index].groupby('calendar_id')['user_name'].value_counts().rename('likes'))
likes_by_user = likes_by_user.join(cals['category'])
likes_by_user[:3]
likes | category | ||
---|---|---|---|
calendar_id | user_name | ||
a-t-brides | ueki05 | 24 | Company |
nishio1873 | 23 | Company | |
rf_p | 22 | Company |
likes_by_user.plot.hist(logy=True, bins=50)
<matplotlib.axes._subplots.AxesSubplot at 0x10fac0ba8>
uu_by_likes = likes_by_user.groupby('calendar_id')['likes'].value_counts(sort=False).rename('uu').reset_index('likes')
uu_by_likes['likes_total'] = uu_by_likes['likes'] * uu_by_likes['uu']
uu_by_likes = pd.DataFrame(uu_by_likes).join(cals[['category', 'likes']].rename(columns={'likes': 'cal_likes'}))
uu_by_likes = uu_by_likes.sort_values(['cal_likes', 'likes'], ascending=[False, True]).set_index('likes', append=True)
uu_by_likes = uu_by_likes.drop('cal_likes', axis=1)
uu_by_likes[:3]
uu | likes_total | category | ||
---|---|---|---|---|
calendar_id | likes | |||
fromscratch | 1 | 341 | 341 | Company |
2 | 52 | 104 | Company | |
3 | 8 | 24 | Company |
uu_by_likes.loc[uu_by_likes['category'] == 'Company'].groupby('likes')[['uu', 'likes_total']].sum().plot.pie(subplots=True, figsize=(12, 6), colormap='Reds', legend=None)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x10f89a6a0>, <matplotlib.axes._subplots.AxesSubplot object at 0x10ebc7668>], dtype=object)
uu_by_likes.loc[uu_by_likes['category'] != 'Company'].groupby('likes')[['uu', 'likes_total']].sum().plot.pie(subplots=True, figsize=(12, 6), colormap='Blues', legend=None)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x10e982668>, <matplotlib.axes._subplots.AxesSubplot object at 0x10e8a10b8>], dtype=object)
fig, ax = plt.subplots(5, 10, figsize=(12, 6))
for axes, (calendar_id, df) in zip(ax.flatten(), uu_by_likes.groupby(level=0, sort=False)['uu']):
colormap = 'Reds' if is_company[calendar_id] else 'Blues'
df.plot.pie(ax=axes, title=calendar_id, colormap=colormap, labels=None)
axes.get_yaxis().set_visible(False)
fig, ax = plt.subplots(5, 10, figsize=(12, 6))
for axes, (calendar_id, df) in zip(ax.flatten(), uu_by_likes.groupby(level=0, sort=False)['likes_total']):
colormap = 'Reds' if is_company[calendar_id] else 'Blues'
df.plot.pie(ax=axes, title=calendar_id, colormap=colormap, labels=None)
axes.get_yaxis().set_visible(False)