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/1e.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (34 sloc)
1.97 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_distance = dd.read_csv('Trips_by_Distance.csv', dtype={'County Name': 'object', | |
'Number of Trips': 'float64', | |
'Number of Trips 1-3': 'float64', | |
'Number of Trips 10-25': 'float64', | |
'Number of Trips 100-250': 'float64', | |
'Number of Trips 25-50': 'float64', | |
'Number of Trips 250-500': 'float64', | |
'Number of Trips 3-5': 'float64', | |
'Number of Trips 5-10': 'float64', | |
'Number of Trips 50-100': 'float64', | |
'Number of Trips <1': 'float64', | |
'Number of Trips >=500': 'float64', | |
'Population Not Staying at Home': 'float64', | |
'Population Staying at Home': 'float64', | |
'Week': 'float64'}) | |
# Group and sum | |
# For Dask DataFrame | |
df_merge = df_distance.groupby('Week')['Population Not Staying at Home'].sum().compute() | |
df_merge = df_merge.astype('int64') | |
print(df_merge) | |
# Barplot | |
plt.figure(figsize=(10, 6)) | |
df_merge.plot(kind='bar', color='orange') | |
plt.title('Number of Participants of Travelers by Distance Trips') | |
plt.xlabel('Week') | |
plt.ylabel('Population Not Staying at Home') | |
plt.xticks(rotation=45) | |
plt.tight_layout() | |
plt.savefig('bar_plot6.png') |