Skip to content
Permalink
e0dd1e5379
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
82 lines (68 sloc) 3.79 KB
import dask.dataframe as dd
import dask
import pandas as pd
import matplotlib.pyplot as plt
import time # import libraries needed
def staying_home():
dataset1 = dd.read_csv('dataset11.csv', dtype={'Population Staying at Home': 'float64'})
home_pop = dataset1.groupby('Week')['Population Staying at Home'].mean().compute()
print(home_pop)
def avg_dist_travelled():
dataset2 = dd.read_csv('dataset22.csv')
trip_columns = ['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']
average_trip_per_week = {}
for column in trip_columns:
average_trip_per_week[column] = dataset2.groupby('Week of Date')[column].mean().compute()
for column, average in average_trip_per_week.items():
print(f"Average distance traveled for {column}:")
print(average)
def identify_dates():
dataset2 = dd.read_csv('dataset22.csv')
trips_10_25_over_10M = dataset2[dataset2['Trips 10-25 Miles'] > 10000000]
dates_10_25_over_10M = trips_10_25_over_10M['Date']
trips_50_100_over_10M = dataset2[dataset2['Trips 50-100 Miles'] > 10000000]
dates_50_100_over_10M = trips_50_100_over_10M['Date']
print("Dates for 10-25 trips with more than 10,000,000 people:")
print(dates_10_25_over_10M.compute())
print("Dates for 50-100 trips with more than 10,000,000 people:")
print(dates_50_100_over_10M.compute())
def processor():
n_processors = [1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10,15, 20]
n_processors_time = {}
for processor_count in n_processors:
start_time = time.time()
with dask.config.set(num_workers=processor_count):
avd_dt = avg_dist_travelled()
dask_time = time.time() - start_time
n_processors_time[processor_count] = dask_time
print(n_processors_time)
def plot():
data = {
'Trips 1-25 Miles': [934957837, 996863262, 1014614495, 1084498325, 984193010, 1052793819, 1040967509],
'Trips 1-3 Miles': [346577279, 358008909, 366533991, 401474049, 347857770, 378936486, 386948113],
'Trips 10-25 Miles': [200922270, 228809869, 235621127, 249988663, 226055368, 245571995, 230580285],
'Trips 100-250 Miles': [8595827, 6535920, 5993704, 5379881, 6259735, 7635743, 7550100],
'Trips 100+ Miles': [15338786, 12563068, 11104823, 8528574, 12892348, 12256537, 12173176],
'Trips 25-100 Miles': [79429125, 86004297, 87599579, 92200386, 84193587, 95005653, 91829556],
'Trips 25-50 Miles': [59517188, 68184743, 70149166, 74381367, 66724543, 74512584, 70644329],
'Trips 250-500 Miles': [2273613, 1941260, 1741994, 1272248, 1957888, 1823661, 1794030],
'Trips 3-5 Miles': [171336406, 178996059, 179210645, 189163336, 179346163, 186257669, 186580557],
'Trips 5-10 Miles': [216121882, 231048425, 233248732, 243872277, 230933709, 242027669, 236858554],
'Trips 50-100 Miles': [19911937, 17819554, 17450413, 17819019, 17469044, 20493069, 21185227],
'Trips 500+ Miles': [4469346, 4085888, 3369125, 1876445, 4674725, 2797133, 2829046]
}
avg_values = [sum(vals) / len(vals) for vals in data.values()]
labels = list(data.keys())
plt.figure(figsize=(12, 6))
plt.bar(labels, avg_values, color='skyblue')
plt.title('Average Number of Participants by Distance-Trips')
plt.xlabel('Distance-Trips')
plt.ylabel('Average Number of Participants')
plt.xticks(rotation=50)
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()
if __name__ == "__main__":
identify_dates()