<jupyter_start><jupyter_text>Recently at work I've been asked to do a few more charts based on pandas dataframes using pyplot. I was hitting a few walls and decided I needed some practice, so I played around with plotting some MBTA reliability data.  To start, I accessed my ArcGIS profile. Mostly just out of habit.<jupyter_code>from arcgis import GIS
gis = GIS(profile='AGOL')
gis.users.me<jupyter_output><empty_output><jupyter_text>I then called the MBTA reliability data and brought it into a spatial dataframe.<jupyter_code>item = gis.content.get("b3a24561c2104422a78b593e92b566d5")
flayer = item.tables[0]
item<jupyter_output><empty_output><jupyter_text>I decided to focus on just the B branch of the green line during off peak hours. This wasn't meant to be any type of analysis, so I was just filtering to keep everything simple.  Also, on-time percentage(otp) isn't actually provided explicitly, so I added that field to do my analysis.<jupyter_code>from arcgis.features import SpatialDataFrame
sdf = flayer.query(where="gtfs_route_id='Green-B' AND peak_offpeak_ind='OFF_PEAK'").sdf
sdf = sdf.sort_values(by=['service_date'],ascending=True)
sdf['otp']=sdf['otp_numerator']/sdf['otp_denominator']
sdf<jupyter_output><empty_output><jupyter_text>Since the main problem I'm having at work was trying to compare date ranges from two parts of the year, that's where I focuesed my efforts. I created two dataframes, one for March/April and the other for October. For some reason the September portion of the data is missing for the Green line, but honestly it doesn't really matter since I'm not actually trying to analyze anything.<jupyter_code>march = sdf[(sdf['service_date']> "2020-03-01") & (sdf['service_date']< "2020-04-30")]
march = march.drop_duplicates(subset=['service_date','gtfs_route_id','otp'],keep='last')
march = march.reset_index(drop=True)
march
october = sdf[(sdf['service_date']> "2020-10-01") & (sdf['service_date']< "2020-10-31")]
october = october.reset_index(drop=True)
october<jupyter_output><empty_output><jupyter_text>The bread and butter. This is the section where I'm playing around with the charts. I'll leave in anything I find interesting.  Documentation I'm pulling from [https://matplotlib.org/3.3.3/tutorials/introductory/pyplot.htmlsphx-glr-tutorials-introductory-pyplot-py]<jupyter_code>import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(15,7))  # Create a figure and an axes.
ax.plot((march.index.values)+1, (march['otp'])*100, label='March/April OTP',linewidth=2, ls='--')  # Plot some data on the axes.
ax.plot(october.index.values+1, (october['otp'])*100, label='October OTP',lw=3)  # Plot more data on the axes...
ax.set_ylim(0,100) #Set y axis limit
ax.set_xlabel('Days into Period')  # Add an x-label to the axes.
ax.set_ylabel('On time Percentage')  # Add a y-label to the axes.
ax.set_title("Green Line B Branch Ontime Percentage")  # Add a title to the axes.
ax.legend()  # Add a legend.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11304931231130493, 'fraction_numerical': 0.025830258302583026, 'mean_word_length': 5.9672897196261685, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '263559', 'license': 'MIT', 'n_tokens_mistral': 1073, 'n_tokens_neox': 991, 'n_words': 317, 'path': 'Pyplot_practice.ipynb', 'repo_name': 'purcellif17/jupyter-playground', 'size': '2981'}