1import pandas as pd2import matplotlib.pyplot as plt3import numpy as np4import requests5from io import StringIO678url = "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/NY%202016%20Party%20Locations-gANytICbCtxX5hfeeGk21AnEZX6Hee.csv"9response = requests.get(url)10data = pd.read_csv(StringIO(response.text))111213data['num_calls'] = pd.to_numeric(data['num_calls'], errors='coerce')141516plt.style.use('default')171819fig, axs = plt.subplots(2, 2, figsize=(24, 24))20fig.suptitle('New York 2016 Party Locations Analysis', fontsize=16)212223borough_counts = data['Borough'].value_counts()24axs[0, 0].bar(borough_counts.index, borough_counts.values)25axs[0, 0].set_title('Distribution of Party Locations by Borough')26axs[0, 0].set_xlabel('Borough')27axs[0, 0].set_ylabel('Number of Locations')28axs[0, 0].tick_params(axis='x', rotation=45)293031top_zips = data.groupby('Incident Zip')['num_calls'].sum().sort_values(ascending=False).head(10)32axs[0, 1].bar(top_zips.index.astype(str), top_zips.values)33axs[0, 1].set_title('Top 10 Zip Codes with Most Party Calls')34axs[0, 1].set_xlabel('Zip Code')35axs[0, 1].set_ylabel('Number of Calls')36axs[0, 1].tick_params(axis='x', rotation=45)373839zip_counts = data['Incident Zip'].value_counts()40pie_data = zip_counts414243colors = plt.cm.viridis(np.linspace(0, 1, len(pie_data)))444546pie_data_sorted = pie_data.sort_values(ascending=False)474849total = pie_data_sorted.sum()50percentages = pie_data_sorted / total * 100515253def make_labels(percentages):54 return [f'{percentages.index[i]}' if p >= 1 else '' for i, p in enumerate(percentages)]5556def make_autopct(percentages):57 def my_autopct(pct):58 return f'{pct:.1f}%' if pct >= 1 else ''59 return my_autopct606162wedges, texts, autotexts = axs[1, 0].pie(pie_data_sorted.values, 63 colors=colors,64 autopct=make_autopct(percentages),65 pctdistance=0.85,66 startangle=90,67 labels=make_labels(percentages),68 labeldistance=1.1) 697071plt.setp(autotexts, size=8, weight="bold")7273plt.setp(texts, size=8)7475axs[1, 0].set_title('Distribution of All Zip Codes by Number of Parties')767778center_circle = plt.Circle((0, 0), 0.70, fc='white')79axs[1, 0].add_artist(center_circle)808182axs[1, 1].scatter(data['Longitude'], data['Latitude'], alpha=0.6, c=data['Borough'].astype('category').cat.codes)83axs[1, 1].set_title('Party Locations in New York City')84axs[1, 1].set_xlabel('Longitude')85axs[1, 1].set_ylabel('Latitude')868788boroughs = data['Borough'].unique()89for i, borough in enumerate(boroughs):90 axs[1, 1].scatter([], [], c=[i], label=borough)91axs[1, 1].legend(title='Borough', loc='center left', bbox_to_anchor=(1, 0.5))929394plt.tight_layout()95plt.show()9697print("Analysis complete. Four plots have been generated and displayed.")