<jupyter_start><jupyter_text>Analysis 1. There is a correlation between number of rides and the average fare per city. Urban cities      the highest number of rides, the highest number of drivers and had the lowest average fare      of the three city types. 2. Urban cities have the highest percentage of total fares at 62.97%. 3. Even though rural cities had the highest average fare per city, the rural cities had the     smallest segment of th total fares by city pie chart at 6.68%. 4. Urban cities had the largest percentage of total rides. 5. Urban cities had the largest percentage of drivers.<jupyter_code># Dependencies

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
#Import city and and ride data csv files.

#City data

city_data = "Resources/city_data.csv"

#Ride data

ride_data = "Resources/ride_data.csv"
#Read city data file with the pandas library.

city_data_df = pd.read_csv(city_data)
city_data_df.head()

#duplicate  city so drop dups
city_data_df = city_data_df.drop_duplicates('city')
city_data_df.head()
# Read ride data file with the pandas library.

ride_data_df = pd.read_csv(ride_data)
ride_data_df.head()
pyber_data = pd.merge(city_data_df, ride_data_df, on="city")
pyber_data.head()
#Find the average fare per city.

average_fare = pyber_data.groupby("city")["fare"].mean()
average_fare
#Find the total rides per city.

total_rides = pyber_data.groupby("city")["ride_id"].count()
total_rides
#Find the total number of drivers per city.

total_drivers = pyber_data.groupby("city")["driver_count"].mean()
total_drivers
city_type = city_data_df.set_index('city')['type']


city_type.value_counts()
pyber_cities = pd.DataFrame({"Average Fare per City":average_fare,
                 "Number of Rides": total_rides,
                 "Number of Drivers": total_drivers,
                 "City Type": city_type
})
pyber_cities.head()
#Urban
urban = pyber_cities.loc[pyber_cities["City Type"]== "Urban"]

#suburban
suburban = pyber_cities.loc[pyber_cities["City Type"]== "Suburban"]

#rural
rural = pyber_cities.loc[pyber_cities["City Type"]== "Rural"]
#Urban
plt.scatter(urban["Number of Rides"], urban["Average Fare per City"], color = "gold", edgecolors="black", s = urban["Number of Drivers"]*20, label = "Urban", alpha = 0.5, linewidth = 1.5)

#Suburban
plt.scatter(suburban["Number of Rides"], suburban["Average Fare per City"], color = "lightskyblue", edgecolors ="black", s = suburban["Number of Drivers"]*20, label = "Suburban", alpha = 0.5, linewidth = 1.5)

#Rural
plt.scatter(rural["Number of Rides"], rural["Average Fare per City"], color = "lightcoral", edgecolors = "black", s = rural["Number of Drivers"]*20, label = "Rural", alpha = 0.5, linewidth = 1.5)

#Add title, x axis label and y axis label.
plt.title("Average Fare per City versus Number of Rides")
plt.xlabel("Number of Rides")
plt.ylabel("Average Fare Per City")
plt.text(40, 50,"Note: Circle size correlates with driver count per city.")

#Add the legend.
plt.legend(loc= "upper right")

#Show plot.
plt.show()
#Sum of fares by city type.

city_fare_pie = pyber_data.groupby(["type"])["fare"].sum()
city_fare_pie
#Use the City Pie index for wedge labels.

city_fare_pie.index
#Set the colors of each section of the pie chart.
colors = ["gold", "lightskyblue", "lightcoral"]

#Only explode the third section of the pie chart.

explode = (0,0, 0.1)

#Create the pie chart.
plt.pie(city_fare_pie, labels = city_fare_pie.index, autopct = "%1.2f%%", colors = colors, explode = explode, shadow = True, startangle = 270)

#Tell Matplotlib that we want a pie chart with equal axes.
plt.axis("equal")

#Add the legend.
plt.legend(loc = "upper right")

#Show the chart.
plt.show()
#Total rides by city type.

city_rides_pie = pyber_data.groupby(["type"])["ride_id"].count()
city_rides_pie
#Use the City Pie index for wedge labels.
city_rides_pie.index

#Set the colors of each section of the pie chart.
colors = ["gold", "lightskyblue", "lightcoral"]

#Only explode the first section of the pie chart.
explode = (0.5,0,0)

#Create the pie chart.
plt.pie(city_rides_pie, labels = city_fare_pie.index, autopct = "%1.2f%%", colors = colors, explode = explode, shadow = True)

#Tell Matplotlib that we wnat the pie chart to have equal axes.
plt.axis("equal")

#Add the legend.
plt.legend(loc = "upper right")

#Show the chart.
plt.show()
#Total driver count.

city_drivers_pie = pyber_data.groupby(["type"])["driver_count"].mean()
city_drivers_pie
#Use the City Pie index for the wedge labels.
city_drivers_pie.index

#Set the colors of each section of the pie chart.
colors = ["gold", "lightskyblue", "lightcoral"]

#explode the first and second segments of the pie chart.

explode = (0.2,0.2,0)

#Create the pie chart.
plt.pie(city_drivers_pie, labels = city_fare_pie.index, autopct = "%1.2f%%", colors = colors, explode = explode, shadow = True)

#Tell Matplotlib that we want the chart to have equal axes.
plt.axis("equal")

#Add the legend.
plt.legend(loc = "upper right")

#Show the pie chart.
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12024443130297655, 'fraction_numerical': 0.011038833037650306, 'mean_word_length': 4.832183908045977, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '305175', 'license': 'MIT', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1689, 'n_words': 582, 'path': 'Pyber.ipynb', 'repo_name': 'ENPlummer/Pyber', 'size': '5073'}