<jupyter_start><jupyter_text>Data Science and Machine Learning Capstone Project  Question 1. Which type of complaint should the Department of Housing Preservation and Development of New York City focus on first?   Table of Contents1. [Data preparation](1)2. [Visualizing and get some insight from data](2)3. [Conclusion](3) ***Data preparation*** First, lets import the necessary libraries and data to answer this.<jupyter_code>import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Import 311 NYC dataset<jupyter_code>columns_used = ['borough', 'city', 'complaint_type', 'created_date', 'incident_address', 'incident_zip', 'latitude', 'location_type', 'longitude','street_name', 'unique_key'] 
df_311= pd.read_csv('fhrw-4uyv.csv', parse_dates = ['created_date'], usecols = columns_used)
df_311.head()<jupyter_output><empty_output><jupyter_text>Preliminary checking for columns type in dataframe.<jupyter_code>df_311.dtypes<jupyter_output><empty_output><jupyter_text>All type of features seems all right. Next, let's check the missing values<jupyter_code>missing_data_311= df_311.isnull()
missing_data_311.head()
for column in missing_data_311.columns.values.tolist():
    print(column)
    #Menghitung jumlah masing-masing nilai unik pada kolom data
    print (missing_data_311[column].value_counts())
    print("")<jupyter_output>borough
False    5619790
Name: borough, dtype: int64

city
False    5535050
True       84740
Name: city, dtype: int64

complaint_type
False    5619790
Name: complaint_type, dtype: int64

created_date
False    5619790
Name: created_date, dtype: int64

incident_address
False    5566873
True       52917
Name: incident_address, dtype: int64

incident_zip
False    5534704
True       85086
Name: incident_zip, dtype: int64

latitude
False    5534730
True       85060
Name: latitude, dtype: int64

location_type
False    5566874
True       52916
Name: location_type, dtype: int64

longitude
False    5534730
True       85060
Name: longitude, dtype: int64

street_name
False    5566873
True       52917
Name: street_name, dtype: int64

unique_key
False    5619790
Name: unique_key, dtype: int64<jupyter_text>There is no missing values for **complaint_type** feature, so let's keep all row in this dataframe as it is for now. Next, Let's check the number of each value of **complaint_type** column.<jupyter_code>df_311['complaint_type'].value_counts()<jupyter_output><empty_output><jupyter_text>***Visualizing and get some insight from data*** Create barh plot to visualize the proportion of the complaints.<jupyter_code># Set colors
colors = ['C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C7', 'C3']
#Set the series
df_311_complaint_type = df_311['complaint_type'].value_counts()
df_311_complaint_type.sort_values(ascending = True, inplace =True)
Total_complaint = df_311_complaint_type.sum()

# Create the barh plot
df_311_complaint_type.plot(kind = 'barh', figsize = (12,12), color = colors)

# Set text label to show the percentage of each complaint
for index, value in enumerate(df_311_complaint_type):
    label =  '{}%'.format(round((value/Total_complaint)*100, 2)) 
    plt.annotate(label, xy=(value + 10000, index-0.1), color='blue')
    
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup