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/1apt1.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (21 sloc)
1.03 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 pandas as pd | |
import matplotlib.pyplot as plt | |
# Reading the Trips by Distance data | |
df = pd.read_csv('Trips_by_Distance.csv') | |
# Since the 'Week' column exists in Trips_by_Distance.csv, proceed with original plan | |
unique_weeks = df['Week'].nunique() | |
avg_population_staying_home = df.groupby('Week')['Population Staying at Home'].mean() | |
df_full = pd.read_csv('Trips_Full Data.csv') | |
trip_distance_columns = [col for col in df_full.columns if 'Trips' in col and 'Miles' in col] | |
avg_trips_by_distance = df_full.groupby('Week of Date')[trip_distance_columns].mean() | |
# Plotting the barplot for People staying at home vs Week | |
plt.figure(figsize=(10, 5)) | |
plt.bar(avg_population_staying_home.index, avg_population_staying_home.values, label='Population Staying at Home') | |
plt.xlabel('Week') | |
plt.ylabel('Average Population Staying at Home') | |
plt.title('Average Population Staying at Home by Week') | |
plt.legend() | |
plt.xticks(rotation=90) | |
plt.tight_layout() | |
# Adjust the path as needed for your environment | |
plt.savefig('population_staying_home_vs_week.png') |