<jupyter_start><jupyter_text>Bubble Plot of Ride Sharing Data<jupyter_code># Obtain the x and y coordinates for each of the three city types
# check the range of total number of rides (x-axis) and average fare (y-axis)

# For urban cities, 
urban_df = merge_df.loc[merge_df["type"] == "Urban", :]
# urban_df.head()

# Find the range of total number of rides within the urban cities
urban_ride_counts = urban_df["city"].value_counts()
urban_max_ride = urban_ride_counts.max()
urban_min_ride = urban_ride_counts.min()

# Find the range of average fare within the urban cities
urban_city_df = urban_df.groupby(["city"])
urban_avg_fare = urban_city_df["fare"].mean()
urban_max_fare = urban_avg_fare.max()
urban_min_fare = urban_avg_fare.min()
# print(urban_avg_fare)

# Find the count of driver in each urban city
urban_driver = urban_city_df["driver_count"].unique()
urban_driver = urban_driver.str[0]
# print(urban_driver.head())

# Concatagate the three tables into one
urban_plot_df = pd.concat([urban_ride_counts, urban_avg_fare, urban_driver], axis=1)
urban_plot_df = pd.DataFrame(urban_plot_df)

print(urban_plot_df.head())
# urban_plot_df.dtypes
# For Suburban cities,
suburban_df = merge_df.loc[merge_df["type"] == "Suburban", :]
# print(suburban_df)

# Find the range of total number of rides within the suburban cities
suburban_ride_counts = suburban_df["city"].value_counts()
suburban_max_ride = suburban_ride_counts.max()
suburban_min_ride = suburban_ride_counts.min()

# Find the range of average fare within the suburban cities
suburban_city_df = suburban_df.groupby(["city"])
suburban_avg_fare = suburban_city_df["fare"].mean()
suburban_max_fare = suburban_avg_fare.max()
suburban_min_fare = suburban_avg_fare.min()

# Find the count of driver in each suburban city
suburban_driver = suburban_city_df["driver_count"].unique()
suburban_driver = suburban_driver.str[0]
# print(suburban_driver.head())

suburban_plot_df = pd.concat([suburban_ride_counts, suburban_avg_fare, suburban_driver], axis=1)
print(suburban_plot_df.head())
# For rural cities,
rural_df = merge_df.loc[merge_df["type"] == "Rural", :]
# Rural_df.head()

# Find the range of total number of rides within the rural cities
rural_ride_counts = rural_df["city"].value_counts()
rural_max_ride = rural_ride_counts.max()
rural_min_ride = rural_ride_counts.min()

# Find the range of average fare within the suburban cities
rural_city_df = rural_df.groupby(["city"])
rural_avg_fare = rural_city_df["fare"].mean()
rural_max_fare = rural_avg_fare.max()
rural_min_fare = rural_avg_fare.min()
# print(rural_max_fare)

# Find the count of driver in each rural city
rural_driver = rural_city_df["driver_count"].unique()
rural_driver = rural_driver.str[0]
# print(suburban_driver.head())

rural_plot_df = pd.concat([rural_ride_counts, rural_avg_fare, rural_driver], axis=1)
print(rural_plot_df.head())
# Incorporate the other graph properties
plt.ylim(18, 48)
plt.xlim(0, 42)

# Create a title, x label, and y label for the chart
plt.title("Pyber Rider Sharing Data (2016)")
plt.xlabel("Total Number of Rides (Per City)")
plt.ylabel("Average Fare ($)")

# Create a legend
legend_elements = [Line2D([0], [0], marker="o", color="red", label="Urban"),
                  Line2D([0], [0], marker="o", color="blue", label="Suburban"),
                  Line2D([0], [0], marker="o", color="yellow", label="Rural")]


plt.legend(handles=legend_elements, loc="upper right")

plt.grid(True)


# Incorporate a text label regarding circle size

plt.text(45, 35, "Note: Circle size correlates with driver count per city.", 
         fontsize=12)


# Build the scatter plots for each city types
plt.scatter(urban_plot_df["city"], urban_plot_df["fare"], marker="o", facecolors="red",
           edgecolors="black", alpha=0.50, s=(urban_plot_df["driver_count"]*10))

plt.scatter(suburban_plot_df["city"], suburban_plot_df["fare"], marker="o", facecolors="blue",
           edgecolors="black", alpha=0.50, s=(suburban_plot_df["driver_count"]*10))

plt.scatter(rural_plot_df["city"], rural_plot_df["fare"], marker="o", facecolors="yellow",
           edgecolors="black", alpha=0.50, s=(rural_plot_df["driver_count"]*10))

# Save Figure
plt.savefig("./Images/Pyber_Rider_Sharing_Data.jpeg")
plt.show()<jupyter_output><empty_output><jupyter_text>Total Fares by City Type<jupyter_code># Calculate Type Percents
total_fare = merge_df["fare"].sum()
urban_fare = urban_df["fare"].sum()
suburban_fare = suburban_df["fare"].sum()
rural_fare = rural_df["fare"].sum()

urban_percent = urban_fare / total_fare
suburban_percent = suburban_fare / total_fare
rural_percent = rural_fare / total_fare
# print(suburban_percent)

# Build Pie Chart
cat = ["Urban", "Suburban", "Rural"]
colors = ["tomato", "lightblue", "yellow"]
explode = (0.2, 0.1, 0.1)
percentage = [urban_percent, suburban_percent, rural_percent]

plt.pie(percentage, explode=explode, labels=cat, colors=colors,
       autopct="%1.1f%%", shadow=True, startangle=60)

plt.axis("equal")

plt.title("% of Total Fares by City Type")

# Save Figure
plt.savefig("./Images/Total_Fares_By_City.jpeg")
plt.show()<jupyter_output><empty_output><jupyter_text>Total Rides by City Type<jupyter_code># Calculate Ride Percents
urban_ride_percent = len(urban_df) / len(merge_df)
suburban_ride_percent = len(suburban_df) / len(merge_df)
rural_ride_percent = len(rural_df) / len(merge_df)
print(urban_ride_percent)


# Build Pie Chart
cat = ["Urban", "Suburban", "Rural"]
colors = ["tomato", "lightblue", "yellow"]
explode = (0.2, 0.1, 0.1)
ride_percentage = [urban_ride_percent, suburban_ride_percent, rural_ride_percent]

plt.pie(ride_percentage, explode=explode, labels=cat, colors=colors,
       autopct="%1.1f%%", shadow=True, startangle=60)

plt.axis("equal")
plt.title("% of Total Rides by City Type")

# Save Figure
plt.savefig("./Images/Total_Rides_By_City.jpeg")
plt.show()<jupyter_output>0.6842105263157895<jupyter_text>Total Drivers by City Type<jupyter_code># Calculate Driver Percents
city = merge_df["city"].unique()
# print(city)
city_df = merge_df.set_index(["city"])
# city_df.head()
city_driver_df = city_df.groupby(level=city_df.index.names).last()
# city_driver_df["driver_count"].count()

# city_driver_df.head()
urban_driver_df = city_driver_df.loc[city_driver_df["type"] == "Urban", :]
suburban_driver_df = city_driver_df.loc[city_driver_df["type"] == "Suburban", :]
rural_driver_df = city_driver_df.loc[city_driver_df["type"] == "Rural", :]

# total_driver = city_driver_df["driver_count"].unique()
total_driver_count = city_driver_df["driver_count"].sum()
# print(total_driver_count)

# urban_driver = urban_driver_df["driver_count"].unique()
urban_driver_count = urban_driver_df["driver_count"].sum()
# print(urban_driver_count)

# suburban_driver = suburban_driver_df["driver_count"].unique()
suburban_driver_count = suburban_driver_df["driver_count"].sum()
# print(suburban_driver_count)

# rural_driver = rural_driver_df["driver_count"].unique()
rural_driver_count = rural_driver_df["driver_count"].sum()
# print(rural_driver_count)

urban_driver_percent = urban_driver_count / total_driver_count
suburban_driver_percent = suburban_driver_count / total_driver_count
rural_driver_percent = rural_driver_count / total_driver_count
# print(urban_driver_percent)

# Build Pie Charts
cat = ["Urban", "Suburban", "Rural"]
colors = ["tomato", "lightblue", "yellow"]
explode = (0.2, 0.1, 0.1)
driver_percentage = [urban_driver_percent, suburban_driver_percent, 
                     rural_driver_percent]

plt.pie(driver_percentage, explode=explode, labels=cat, colors=colors,
       autopct="%1.1f%%", shadow=True, startangle=60)

plt.axis("equal")
plt.title("% of Total Drivers by City Type")

# Save Figure
plt.savefig("./Images/Total_Drivers_By_City.jpeg")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13663163291463729, 'fraction_numerical': 0.012048192771084338, 'mean_word_length': 6.748758689175769, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '428357', 'license': 'MIT', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2732, 'n_words': 552, 'path': 'Pyber/pyber_starter.ipynb', 'repo_name': 'NormanLo4319/MatPlotLib-Challenge', 'size': '7802'}