<jupyter_start><jupyter_text>Pyber Challenge<jupyter_code># Add Matplotlib inline magic command
%matplotlib inline
# Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd

# Files to load
city_data_to_load = "./Resources/city_data.csv"
ride_data_to_load = "./Resources/ride_data.csv"
# Read the city data file and store it in a pandas DataFrame.
city_data_df = pd.read_csv(city_data_to_load)
city_data_df.head(10)
# Read the ride data file and store it in a pandas DataFrame.
ride_data_df = pd.read_csv(ride_data_to_load)
ride_data_df.head(10)
# Combine the data into a single dataset
pyber_data_df = pd.merge(ride_data_df, city_data_df, how="left", on=["city", "city"])
# Display the DataFrame
pyber_data_df.head()<jupyter_output><empty_output><jupyter_text>Challenge 1 - To create the summary DataFrame<jupyter_code># Get total rides for each city types
total_rides_by_type = pyber_data_df.groupby(["type"]).count()["ride_id"]
total_rides_by_type 
# Get total drivers for each city types
total_drivers_by_type = city_data_df.groupby(["type"]).sum()["driver_count"]
total_drivers_by_type 
# Get the total fares for each city types
total_fare_by_type = pyber_data_df.groupby(["type"]).sum()["fare"]
total_fare_by_type 
# Get the average fare per ride for each city types
avg_fare_per_ride = total_fare_by_type/ total_rides_by_type
avg_fare_per_ride 
# Get the average fare per driver for each city types
avg_fare_per_driver = total_fare_by_type/ total_drivers_by_type
avg_fare_per_driver
summary = {
    "Total Rides": total_rides_by_type,
    "Total Drivers": total_drivers_by_type,
    "Total Fares": total_fare_by_type,
    "Average Fare per Ride": avg_fare_per_ride,
    "Average Fare per Driver": avg_fare_per_driver,
}
pyber_ride_summary_df = pd.DataFrame(summary)
pyber_ride_summary_df
#Delete the index name
#del pyber_ride summary_df.index.name
pyber_ride_summary_df.index.name = ""

# Format the columns
pyber_ride_summary_df["Total Rides"] = pyber_ride_summary_df["Total Rides"].map("{:,}".format)
pyber_ride_summary_df["Total Drivers"] = pyber_ride_summary_df["Total Drivers"].map("{:,}".format)
pyber_ride_summary_df["Total Fares"] = pyber_ride_summary_df["Total Fares"].map("${:,.2f}".format)
pyber_ride_summary_df["Average Fare per Ride"] = pyber_ride_summary_df["Average Fare per Ride"].map("${:,.2f}".format)
pyber_ride_summary_df["Average Fare per Driver"] = pyber_ride_summary_df["Average Fare per Driver"].map("${:,.2f}".format)
pyber_ride_summary_df<jupyter_output><empty_output><jupyter_text>Challenge 2 Create Multiple-Line Plot for the Sum of the Fares for Each City Type<jupyter_code># Rename columns
pyber_data_df = pyber_data_df.rename(columns={
    'city':'City', 
    'date':'Date',
    'fare':'Fare', 
    'ride_id': 'Ride Id',
    'driver_count': 'No. Drivers', 
    'type':'City Type'
})
pyber_data_df
# Set the index to the "Date" column
pyber_data_df.set_index(pyber_data_df["Date"], inplace=True)
pyber_data_df
#Create a new DataFrame for fares, and include only the City Type and Fare columns 
column_names = ["Date", "City Type", "Fare"]
pyber_cities_fare = pyber_data_df[column_names].copy()
pyber_cities_fare
# Drop the extra column
pyber_cities_fare.drop(["Date"],axis=1,inplace=True)
pyber_cities_fare.index = pd.to_datetime(pyber_data_df.index)
pyber_cities_fare.head()
pyber_cities_fare.info()
#Calculate the sum() of fares by the type of city and date using groupby() to create a Series.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11056863871338311, 'fraction_numerical': 0.002871912693854107, 'mean_word_length': 6.880090497737557, 'pattern_counts': {'":': 5, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '177073', 'license': 'MIT', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1256, 'n_words': 292, 'path': '.ipynb_checkpoints/Pyber_Challenge-checkpoint.ipynb', 'repo_name': 'aindrilachatterjee12345/PyBer_Analysis', 'size': '3482'}