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 pandas as pd
import matplotlib.pyplot as plt
# Load the dataset
df = pd.read_csv('Trips_by_Distance.csv')
def plot_participants_by_trip_distance():
# Define the trip distance categories
trip_categories = [
"Number of Trips <1",
"Number of Trips 1-3",
"Number of Trips 3-5",
"Number of Trips 5-10",
"Number of Trips 10-25",
"Number of Trips 25-50",
"Number of Trips 50-100",
"Number of Trips 100-250",
"Number of Trips 250-500",
"Number of Trips >=500",
]
# Calculate the total number of participants in each category
total_participants = df[trip_categories].sum()
# Create a bar chart
plt.figure(figsize=(12, 8))
plt.bar(trip_categories, total_participants, color='skyblue', alpha=0.8)
plt.xlabel("Trip Distance Category")
plt.ylabel("Total Participants")
plt.title("Total Participants by Trip Distance Category")
plt.xticks(rotation=45, ha="right")
plt.grid(True, axis='y')
plt.tight_layout()
plt.show()
# Invoke the plotting function
plot_participants_by_trip_distance()