SWG7i




Pay Notebook Creator: Karsh Patel0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [1]:
# Crosscompute
target_folder = '/tmp'
In [2]:
import pandas
import matplotlib
from matplotlib import pyplot as plt
In [3]:
d = pandas.read_csv('NYC_Social_Media_Usage.csv')
In [4]:
t = d[['Platform', 'Likes/Followers/Visits/Downloads']]
t
Out[4]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Platform Likes/Followers/Visits/Downloads
0 SMS 61652.0
1 SMS 44547.0
2 Flickr NaN
3 Newsletter NaN
4 Twitter 389.0
5 Twitter 431.0
6 Android 5026.0
7 Android NaN
8 Android 313.0
9 Broadcastr NaN
10 Broadcastr NaN
11 Facebook 3.0
12 Facebook 36.0
13 Facebook 47.0
14 Facebook 90.0
15 Facebook 105.0
16 Facebook 123.0
17 Facebook 119.0
18 Facebook 148.0
19 Facebook 197.0
20 Facebook 179.0
21 Facebook 200.0
22 Facebook 200.0
23 Facebook 183.0
24 Facebook 190.0
25 Facebook 227.0
26 Facebook 194.0
27 Facebook 243.0
28 Facebook 237.0
29 Facebook 234.0
... ... ...
5869 YouTube 44.0
5870 YouTube 53.0
5871 YouTube 62.0
5872 YouTube 44.0
5873 YouTube 60.0
5874 YouTube 98.0
5875 YouTube 101.0
5876 YouTube 163.0
5877 YouTube 256.0
5878 YouTube 311.0
5879 YouTube 381.0
5880 YouTube 1338.0
5881 YouTube 3649.0
5882 YouTube 196.0
5883 YouTube 2097.0
5884 Youtube 12.0
5885 YouTube 32.0
5886 YouTube 0.0
5887 Youtube 245.0
5888 YouTube 19.0
5889 YouTube 4.0
5890 Youtube 23.0
5891 YouTube 18.0
5892 YouTube 40.0
5893 Youtube 31.0
5894 Youtube 4.0
5895 YouTube 89.0
5896 Facebook 1062.0
5897 Google+ 16.0
5898 TOTAL 2785806.0
<p>5899 rows × 2 columns</p>
In [5]:
t = t.dropna()
In [6]:
t
Out[6]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Platform Likes/Followers/Visits/Downloads
0 SMS 61652.0
1 SMS 44547.0
4 Twitter 389.0
5 Twitter 431.0
6 Android 5026.0
8 Android 313.0
11 Facebook 3.0
12 Facebook 36.0
13 Facebook 47.0
14 Facebook 90.0
15 Facebook 105.0
16 Facebook 123.0
17 Facebook 119.0
18 Facebook 148.0
19 Facebook 197.0
20 Facebook 179.0
21 Facebook 200.0
22 Facebook 200.0
23 Facebook 183.0
24 Facebook 190.0
25 Facebook 227.0
26 Facebook 194.0
27 Facebook 243.0
28 Facebook 237.0
29 Facebook 234.0
30 Facebook 238.0
31 Facebook 287.0
32 Facebook 257.0
33 Facebook 282.0
34 Facebook 272.0
... ... ...
5869 YouTube 44.0
5870 YouTube 53.0
5871 YouTube 62.0
5872 YouTube 44.0
5873 YouTube 60.0
5874 YouTube 98.0
5875 YouTube 101.0
5876 YouTube 163.0
5877 YouTube 256.0
5878 YouTube 311.0
5879 YouTube 381.0
5880 YouTube 1338.0
5881 YouTube 3649.0
5882 YouTube 196.0
5883 YouTube 2097.0
5884 Youtube 12.0
5885 YouTube 32.0
5886 YouTube 0.0
5887 Youtube 245.0
5888 YouTube 19.0
5889 YouTube 4.0
5890 Youtube 23.0
5891 YouTube 18.0
5892 YouTube 40.0
5893 Youtube 31.0
5894 Youtube 4.0
5895 YouTube 89.0
5896 Facebook 1062.0
5897 Google+ 16.0
5898 TOTAL 2785806.0
<p>3979 rows × 2 columns</p>
In [7]:
labels = t.Platform.values
values=t['Likes/Followers/Visits/Downloads'].values
In [8]:
s = t.groupby('Platform').sum()
In [9]:
t.columns
Out[9]:
Index(['Platform', 'Likes/Followers/Visits/Downloads'], dtype='object')
In [10]:
d = pandas.read_csv('NYC_Social_Media_Usage.csv')
t = d[['Platform', 'Likes/Followers/Visits/Downloads']]
t = t.dropna()
labels = t.Platform.values
values=t['Likes/Followers/Visits/Downloads'].values
s = t.groupby('Platform').sum()
In [11]:
s.index
Out[11]:
Index(['Android', 'Facebook', 'Flickr', 'Foursquare',
       'Foursquare (Badge Unlock)', 'Google+', 'Instagram', 'Linked-In',
       'Newsletter', 'Pinterest', 'SMS', 'TOTAL', 'Tumblr', 'Twitter',
       'WordPress', 'YouTube', 'Youtube', 'iPhone', 'iPhone App',
       'iPhone app'],
      dtype='object', name='Platform')
In [12]:
s = s.drop('TOTAL')
In [13]:
f3,ax3=plt.subplots()
ax3.pie(s.values, labels=s.index)
ax3.axis('equal')
Out[13]:
(-1.133674544095993,
 1.1016035497188568,
 -1.1015438199043275,
 1.1310853123664857)
In [14]:
s.plot.pie(s.columns[0])
Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fc19e02bc18>
In [15]:
f3,ax3=plt.subplots()
ax3.axis('equal')
s.plot(y=s.columns[0], kind='pie', labels=['' for x in range(len(s.index))], ax=ax3, title=s.index.name, fontsize=10)
ax3.legend(loc=3, labels=s.index,bbox_to_anchor=(-0.30,0))
ax3.set_ylabel('')
Out[15]:
<matplotlib.text.Text at 0x7fc19be04630>
In [16]:
s.columns
Out[16]:
Index(['Likes/Followers/Visits/Downloads'], dtype='object')
In [17]:
s.loc['foursquare'] = s.loc['Foursquare'] + s.loc['Foursquare (Badge Unlock)']
In [18]:
s
Out[18]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Foursquare 516954.0
Foursquare (Badge Unlock) 85310.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
YouTube 106212.0
Youtube 3333.0
iPhone 98417.0
iPhone App 529987.0
iPhone app 336230.0
foursquare 602264.0
In [19]:
s = s.drop('Foursquare')
s = s.drop('Foursquare (Badge Unlock)')
In [20]:
s
Out[20]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
YouTube 106212.0
Youtube 3333.0
iPhone 98417.0
iPhone App 529987.0
iPhone app 336230.0
foursquare 602264.0
In [21]:
s.loc['youtube'] = s.loc['YouTube'] + s.loc['Youtube']
In [22]:
s
Out[22]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
YouTube 106212.0
Youtube 3333.0
iPhone 98417.0
iPhone App 529987.0
iPhone app 336230.0
foursquare 602264.0
youtube 109545.0
In [23]:
s = s.drop('YouTube')
s = s.drop('Youtube')
In [24]:
s
Out[24]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
iPhone 98417.0
iPhone App 529987.0
iPhone app 336230.0
foursquare 602264.0
youtube 109545.0
In [25]:
s.loc['iphone'] = s.loc['iPhone'] + s.loc['iPhone App'] + s.loc['iPhone app']
In [26]:
s
Out[26]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
iPhone 98417.0
iPhone App 529987.0
iPhone app 336230.0
foursquare 602264.0
youtube 109545.0
iphone 964634.0
In [27]:
s = s.drop('iPhone')
s = s.drop('iPhone App')
s = s.drop('iPhone app')
In [28]:
s
Out[28]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Likes/Followers/Visits/Downloads
Platform
Android 26328.0
Facebook 6870824.0
Flickr 157881.0
Google+ 34.0
Instagram 134617.0
Linked-In 461482.0
Newsletter 18067849.0
Pinterest 565.0
SMS 999040.0
Tumblr 573950.0
Twitter 8095134.0
WordPress 94795.0
foursquare 602264.0
youtube 109545.0
iphone 964634.0
In [29]:
f3,ax3=plt.subplots()
ax3.axis('equal')
s.plot(y=s.columns[0], kind='pie', labels=['' for x in range(len(s.index))], ax=ax3, title=s.index.name, fontsize=10)
ax3.legend(loc=3, labels=s.index,bbox_to_anchor=(-0.070,0))
ax3.set_ylabel('')
Out[29]:
<matplotlib.text.Text at 0x7fc19bc5b1d0>
In [30]:
from os.path import join

pathname = join(target_folder, 'piechart.png')
f3.savefig(pathname)
print('piechart_image_path = %s' % pathname)
piechart_image_path = /tmp/piechart.png
In [ ]:
 
In [ ]: