Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
BIG-data/1apt2(first draft).py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (23 sloc)
1.19 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import pandas as pd | |
df_full = pd.read_csv('Trips_Full Data.csv') | |
distance_columns = [ | |
'Trips <1 Mile', 'Trips 1-25 Miles', 'Trips 1-3 Miles', 'Trips 10-25 Miles', | |
'Trips 100-250 Miles', 'Trips 100+ Miles', 'Trips 25-100 Miles', 'Trips 25-50 Miles', | |
'Trips 250-500 Miles', 'Trips 3-5 Miles', 'Trips 5-10 Miles', 'Trips 50-100 Miles', | |
'Trips 500+ Miles' | |
] | |
weekly_average = df_full.groupby('Week of Date')[distance_columns].mean() | |
weekly_average = weekly_average.reset_index().melt(id_vars=['Week of Date'], var_name='Distance Category', value_name='Average Trips') | |
plt.figure(figsize=(10, 7)) | |
for category in weekly_average['Distance Category'].unique(): | |
subset = weekly_average[weekly_average['Distance Category'] == category] | |
plt.bar(subset['Week of Date'], subset['Average Trips'], label=category) | |
plt.xlabel("Week") | |
plt.ylabel("Average Number of Trips") | |
plt.title("Average Number of Trips per Week by Distance Category") | |
plt.legend(title='Distance Category') | |
plt.xticks(rotation=90) # Rotate the x-axis labels for better readability | |
plt.grid(True) # Display grid | |
plt.show() | |
plt.savefig('Average Number of Trips per Week by Distance Category'.png') |