Skip to content
Permalink
main
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
import csv
import numpy as np
import pandas as pd
from IPython.display import display
from dask import dataframe as dd
import dask.dataframe as dd
import dask.array as da
import dask.bag as db
# Graph visualisation does not work without this.
import matplotlib
matplotlib.use('Agg') # Use the Agg backend
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
import matplotlib.dates as mdates
from datetime import datetime
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
# Load the CSV file using Dask
ddd = dd.read_csv('Trips_by_Distance.csv', usecols=['Week', 'Number of Trips 10-25', 'Number of Trips 50-100'], dtype={'Number of Trips 10-25': 'float64', 'Number of Trips 50-100' : 'float64'})
# Trips 10-25
grouped_ddd = ddd.groupby('Week')
combined_ddd = grouped_ddd['Number of Trips 10-25'].sum().reset_index() # Combining duplicate weeks
# Identify the weeks that > 10000000 people conducted 10-25 Number of Trips and compare them to > 10000000 people who did 50-100 Number of trips
popfilter = combined_ddd[combined_ddd['Number of Trips 10-25'] > 100000000] # Filter by weeks greater than 10000000
weeks_list = popfilter['Week'].to_dask_array().compute().tolist() # Put the weeks into a list for easier plotting
# No need to convert to datetime because it's already numeric
# Plot the scatter plot
plt.scatter(x=weeks_list, y=popfilter["Number of Trips 10-25"].to_dask_array(lengths=True).compute())
plt.title('Scatter plot of weeks where > 10000000 people conducted 10-25 number of trips')
plt.xlabel('Week')
plt.ylabel('Number of Trips 10-25')
plt.savefig('scatter1.png')
# Trips 50-100
grouped_ddd_50_100 = ddd.groupby('Week')
combined_ddd_50_100 = grouped_ddd_50_100['Number of Trips 50-100'].sum().reset_index()
# Identify the weeks that > 10000000 people conducted 50-100 Number of Trips
popfilter_50_100 = combined_ddd_50_100[combined_ddd_50_100['Number of Trips 50-100'] > 10000000]
weeks_list_50_100 = popfilter_50_100['Week'].to_dask_array().compute().tolist()
# No need to convert to datetime because it's already numeric
# Plot the scatter plot for Trips 50-100
plt.scatter(x=weeks_list_50_100, y=popfilter_50_100["Number of Trips 50-100"].to_dask_array(lengths=True).compute())
plt.title('Scatter plot of weeks where > 10000000 people conducted 50-100 number of trips')
plt.xlabel('Week')
plt.ylabel('Number of Trips 50-100')
plt.savefig('scatter2.png')