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?
5011-BIG-DATA/number1b.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51 lines (38 sloc)
1.98 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 pandas as pd | |
import matplotlib.pyplot as plt | |
# Step 1: Load Data | |
data = pd.read_csv("trips_by_distance.csv") | |
# Step 2: Data Filtering | |
# Filter data for > 10,000,000 people conducting 10-25 trips | |
filtered_data_10_25 = data[(data['Number of Trips 10-25'] > 0) & (data['Number of Trips 10-25'] < 100) & (data['Population Not Staying at Home'] > 10000000)] | |
# Filter data for > 10,000,000 people conducting 50-100 trips | |
filtered_data_50_100 = data[(data['Number of Trips 50-100'] > 0) & (data['Number of Trips 50-100'] < 100) & (data['Population Not Staying at Home'] > 10000000)] | |
# Step 3: Extract Dates | |
# Get dates where > 10,000,000 people conducted 10-25 trips | |
dates_10_25 = filtered_data_10_25['Date'].unique() | |
# Get dates where > 10,000,000 people conducted 50-100 trips | |
dates_50_100 = filtered_data_50_100['Date'].unique() | |
# Step 4: Comparison | |
# Print dates for > 10,000,000 people conducted 10-25 trips | |
print("Dates where > 10,000,000 people conducted 10-25 trips:") | |
print(dates_10_25) | |
# Print dates for > 10,000,000 people conducted 50-100 trips | |
print("Dates where > 10,000,000 people conducted 50-100 trips:") | |
print(dates_50_100) | |
# Step 5: Visualization | |
plt.figure(figsize=(10, 6)) | |
# Plot total population (assuming it's represented by Population Not Staying at Home) | |
plt.plot(data['Date'], data['Population Not Staying at Home'], label='Total Population Not Staying at Home') | |
# Plot > 10,000,000 people conducting 10-25 trips | |
plt.scatter(filtered_data_10_25['Date'], filtered_data_10_25['Population Not Staying at Home'], color='red', label='> 10,000,000 people (10-25 trips)') | |
# Plot > 10,000,000 people conducting 50-100 trips | |
plt.scatter(filtered_data_50_100['Date'], filtered_data_50_100['Population Not Staying at Home'], color='green', label='> 10,000,000 people (50-100 trips)') | |
# Add labels and legend | |
plt.xlabel('Date') | |
plt.ylabel('Population Not Staying at Home') | |
plt.title('Population Not Staying at Home vs. Date') | |
plt.legend() | |
plt.xticks(rotation=45) | |
plt.tight_layout() | |
# Show plot | |
plt.show() |