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?
DataProject/1efinal.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (46 sloc)
2.11 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 | |
matplotlib.use('Agg') # Use the Agg backend | |
import dask.dataframe as dd | |
import matplotlib.pyplot as plt | |
# Read data using Dask | |
df_data = dd.read_csv('Trips_Full_Data.csv', dtype = {'Trips 1-25 Miles': 'float64', | |
'Trips 1-3 Miles': 'float64', | |
'Trips 10-25 Miles': 'float64', | |
'Trips 100-250 Miles': 'float64', | |
'Trips 25-50 Miles': 'float64', | |
'Trips 250-500 Miles': 'float64', | |
'Trips 3-5 Miles': 'float64', | |
'Trips 5-10 Miles': 'float64', | |
'Trips 50-100 Miles': 'float64', | |
'Trips <1 Mile': 'float64', | |
'Trips >=500 Miles': 'float64', | |
'Population Not Staying at Home': 'float64', | |
'Population Staying at Home': 'float64', | |
'Week': 'float64' | |
}) | |
Trips = [ | |
'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' | |
] | |
# Group and sum | |
df_merge = df_data[Trips].sum().compute() | |
print(df_merge) | |
# Plot | |
plt.figure(figsize=(10, 6)) | |
df_merge.plot(kind='bar', color='orange') | |
plt.title('Number of Participants of Travelers by Distance Trips') | |
plt.xlabel('Number of Trips by Distance') | |
plt.ylabel('Population Not Staying at Home') | |
plt.xticks(rotation=45) | |
plt.tight_layout() | |
plt.savefig('bar_plot11data.png') |