There's more...

Although typically frowned upon by data visualization gurus, pandas can create pie charts. In this instance, we use them to see snapshots of the total group distribution over time. Let's first select every third month of data, beginning 18 months prior to the end of data collection. We use the asfreq method, which only works on DataFrames with datetime values in the index. The offset alias 3MS is used to represent the start of every third month. Because group_cum_pct is aggregated by week, the first day of the month is not always present. We set the method parameter to bfill, which stands for backfill; it will look back in time to find the first day of the month that has data in it. We then use the to_period method (which also only works with datetimes in the index) to change the values in the index to a pandas period of time. Finally, we transpose the data so that each column represents the distribution of members in the meetup group for that month:

>>> pie_data = group_cum_pct.asfreq('3MS', method='bfill') 
.tail(6).to_period('M').T
>>> pie_data

From here, we can use the plot method to create the pie charts:

>>> from matplotlib.cm import Greys
>>> greys = Greys(np.arange(50,250,40))

>>> ax_array = pie_data.plot(kind='pie', subplots=True,
layout=(2,3), labels=None,
autopct='%1.0f%%', pctdistance=1.22,
colors=greys)
>>> ax1 = ax_array[0, 0]
>>> ax1.figure.legend(ax1.patches, pie_data.index, ncol=3)
>>> for ax in ax_array.flatten():
ax.xaxis.label.set_visible(True)
ax.set_xlabel(ax.get_ylabel())
ax.set_ylabel('')
>>> ax1.figure.subplots_adjust(hspace=.3)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.72.176