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?
5011CEM_COURSEWORK_CLINTON-EKWUGHA_13293446/5.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20 lines (15 sloc)
786 Bytes
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 | |
# Load the data from CSV file | |
data_file = "/Users/thecreator/Downloads/Trips_by_Distance.csv" | |
df = pd.read_csv(data_file) | |
# Check the column names to find the exact name to use | |
print(df.columns) | |
# Assuming the correct column name is 'Number of Trips 0-1 Miles', filter and sum | |
if 'Number of Trips 0-1 Miles' in df.columns: | |
# Filter data where 'Number of Trips 0-1 Miles' is greater than 0 | |
home_stayers = df[df['Number of Trips 0-1 Miles'] > 0] | |
# Calculate the total number of people who stayed home | |
total_home_stayers = home_stayers['Number of Trips 0-1 Miles'].sum() | |
print(f"Total number of people who stayed home: {total_home_stayers}") | |
else: | |
print("Column 'Number of Trips 0-1 Miles' not found in the DataFrame. Check column names.") |