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?
5011CEM_SourceCode/Task 1 (a).py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (42 sloc)
1.5 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
#!/usr/bin/env python | |
# coding: utf-8 | |
# In[1]: | |
import pandas as pd | |
import numpy as np | |
import dask.dataframe as dd | |
df=dd.read_csv('Cleaned_Trips_by_Distance.csv') | |
df['Week'].nunique().compute() | |
df.groupby(by = 'Week')['Population Staying at Home'].mean().compute() | |
# In[2]: | |
import matplotlib.pyplot as plt | |
grouped_data = df.groupby('Week')['Population Staying at Home'].mean().compute() | |
plt.figure(figsize=(10, 6)) | |
grouped_data.plot(kind='bar') | |
plt.title('BarChart of People Staying at Home vs Week') | |
plt.xlabel('Week') | |
plt.ylabel('Average Population Staying at Home') | |
plt.show() | |
# In[5]: | |
df_full=pd.read_csv("Trips_Full Data.csv") | |
df_full=df_full.drop(columns=['Trips']) | |
# In[6]: | |
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
df_full = pd.read_csv('Trips_Full Data.csv') | |
trip_columns = ['Trips <1 Mile', 'Trips 1-3 Miles', 'Trips 3-5 Miles', | |
'Trips 5-10 Miles', 'Trips 10-25 Miles', 'Trips 25-50 Miles', | |
'Trips 50-100 Miles', 'Trips 100-250 Miles', 'Trips 250-500 Miles', | |
'Trips 500+ Miles'] | |
average_values = df_full[trip_columns].mean() | |
print(average_values) | |
import seaborn as sns | |
plt.figure(figsize=(12, 8)) | |
sns.barplot(x=average_values.index, y=average_values.values, palette='viridis') | |
plt.xlabel('Distance Range', fontsize=12) | |
plt.ylabel('Average Number of Trips', fontsize=12) | |
plt.title('Average Number of Trips for Each Distance Range', fontsize=14) | |
plt.xticks(rotation=45, ha='right') | |
plt.tight_layout() | |
plt.show() | |
# In[ ]: | |