I am working on the file "MBA_S16/White-DeveloperDemographics.ipynb".
The first task is:
Do clusters of CompSci programs in a state make female participation more likely?
Is there a correlation between the number of schools with Computer Science programs and women participating in the program?
From the analysis below, it's clear that a higher concentration of schools in each state correlates to a higher participation rate in women. It's not clear if this is because interest in general might be higher, or states with higher concentrations of these programs are actually helping to encourage women to participate.
Further, this is not a guarantee, as there are states with high concentrations of programs not breaking the 400 women ceiling.
Can you write Python code for it?

ap1= sns.swarmplot(y="# schools", x="# female", data=ap, split = True)
fig_cluster = ap1.get_figure()


I am working on the file "MBA_S16/White-DeveloperDemographics.ipynb".
The first task is:
Do larger or smaller classes encourage female participation better?
From the analysis below, it seems as though, once class size exceeds 10, female participation is much higher. Like much of the analysis in this document, it is not clear whether female participation is higher because overall demand is higher in some states than others (hence the larger classes), or if larger classes encourage female participation (easier to blend in, etc.)
Can you write Python code for it?

ap2= sns.swarmplot(y="yield per teacher", x="# female", data=ap, split = True)
fig_cluster = ap1.get_figure()


I am working on the file "MBA_S16/White-DeveloperDemographics.ipynb".
The first task is:
Does size matter: is there a relationship between the number of men/women taking the test and their pass rates?
On the whole, based on the results of the analysis below, it is safe to say that having more people in your state take the exam does not greatly impact the rate in which people pass.
However, this analysis also shows that, as a cohort, women are being slightly outperformed by men. Is there a bias in the AP exam or coursework? Are women not finding resources they need as readily? That is not clear from the data, but the performance here is a huge concern. If women are not doing as well on the AP exam for some reason, are they more likely to drop out instead of improve?
Can you write Python code for it?

sns.set(style="whitegrid")
sns.set_color_codes("pastel")
sns.factorplot(x="# male", y="% male passed", data=ap,
            label="Male Test Takers", color="b")
sns.set_color_codes("muted")
sns.factorplot(x="# female", y="% fem passed", data=ap,
            label="Female Test Takers", color="g")


I am working on the file "MBA_S16/White-DeveloperDemographics.ipynb".
The first task is:
Girl Power: Does having girlfriends with you increase women's odds of passing?
States have a lot of variability in encouraging female participation in the Computer Science AP Exam, and in getting higher rates of women to pass the AP exam. It's clear that living in California gains you the best odds of being a female who took and passed the exam. As this exam is administered for another 4 or 5 years, and more schools start administering it, we may see these rates increase.
Can you write Python code for it?

sns.set(style="whitegrid")
f, ax = plt.subplots(figsize=(20,25))

sns.set_color_codes("pastel")
sns.barplot(x="# female", y="2013 data", data=ap,
            label="Female Not Passed", color="r")
sns.set_color_codes("muted")
sns.barplot(x="# female passed", y="2013 data", data=ap,
            label="Female Passed", color="r")

ax.legend(ncol=2, loc="lower right", frameon=True)
ax.set(xlim=(0, 1000), ylabel="",
       xlabel="Passed Females as a Proportion of Not Passed Females")
sns.despine(left=True, bottom=True)


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
4. Economic Analysis & Visualization
4|1 Unemployment
First, let's examine the overall unemployment trends from 1950 to 2016. To do this, we take the FRED database panda, set the dates (1950-2016), and adjust the aspect ratio, titles, and other stylistic components.
Can you write Python code for it?

start, end = dt.datetime(1950, 2, 1), dt.datetime(2015, 1, 1)
data = web.DataReader(['UNRATE'],'fred', start, end)
data.columns = ['Unemployment Rate']
plt.figure(figsize=plt.figaspect(0.25))

data['Unemployment Rate'].plot()
plt.text(dt.datetime(1950, 1, 1), 1, 'c. FRED Database', fontsize=10, weight='regular')
plt.suptitle('Figure 1. Unemployment Rate, 1950-2015', fontsize=20, weight='bold')
plt.show()


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
5. Political Analysis & Visualization
Now, we will take the political datasets we cleaned up and spliced above and visualize them to better see the trends. The political datasets do not have a strict year because Congress serves on a two-year term, but the year 1950 occurred during the 81st Congress and the 115th came into office by 2015.
Can you write Python code for it?

plt.figure(figsize=plt.figaspect(.2))
p1 = plt.scatter(senatedem['Years'], senatedem['Seats'], color = 'blue')
p2 = plt.scatter(senategop['Years'], senategop['Seats'], color = 'red')
plt.legend((p1,p2),('Senate Democrats', 'Senate Republicans'),numpoints=1, loc='best')
plt.xlabel('Year')
plt.ylabel('Seats')
plt.suptitle('Figure 3. Party Seats in the Senate, 1950-2015', fontsize=20, weight='bold')
plt.show()

plt.figure(figsize=plt.figaspect(.2))
p3 = plt.scatter(housedem['Years'], housedem['Seats'], color = 'blue')
p4 = plt.scatter(housegop['Years'], housegop['Seats'], color = 'red')
plt.legend((p3,p4),('House Democrats', 'House Republicans'),numpoints=1, loc='best')
plt.xlabel('Year')
plt.ylabel('Seats')
plt.suptitle('Figure 3. Party Seats in the House, 1950-2015', fontsize=20, weight='bold')
plt.show()


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
As we can see in the chart above, there have been ebbs and flows in both the Senate and the House of Representatives, with the Democrats dominating both chambers from the 86th Congress (1959-1961) until the 104th Congress (1995-1997).
6. The Role of Economic Factors in Political Shifts
Bringing it all together, for the final step we will merge the economic data with the political trend data above.
Can you write Python code for it?

start, end = dt.datetime(1950, 2, 1), dt.datetime(2015, 1, 1)
data = web.DataReader(['UNRATE', 'USREC'],'fred', start, end)
data.columns = ['Unemployment Rate', 'Recession']
plt.figure(figsize=plt.figaspect(0.25))
data['Unemployment Rate'].plot()
plt.text(dt.datetime(1948, 1, 1), 1, 'c. FRED Database', fontsize=10, weight='regular')
plt.suptitle('Figure 4. US House Impact of Economic Conditions, 1950-2015', fontsize=20, weight='bold')
p3 = plt.scatter(housedem['Years'], housedem['Seats'], color = 'blue')
p4 = plt.scatter(housegop['Years'], housegop['Seats'], color = 'red')
hl_recession(recession_months())

start, end = dt.datetime(1950, 2, 1), dt.datetime(2015, 1, 1)
data = web.DataReader(['UNRATE', 'USREC'],'fred', start, end)
data.columns = ['Unemployment Rate', 'Recession']
plt.figure(figsize=plt.figaspect(0.25))
data['Unemployment Rate'].plot()
plt.text(dt.datetime(1948, 1, 1), 1, 'c. FRED Database', fontsize=10, weight='regular')
plt.suptitle('Figure 4. US Senate Impact of Economic Conditions, 1950-2015', fontsize=20, weight='bold')
p3 = plt.scatter(senatedem['Years'], senatedem['Seats'], color = 'blue')
p4 = plt.scatter(senategop['Years'], senategop['Seats'], color = 'red')
hl_recession(recession_months())


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
Before we proceed, I want to check the types of the values in my DataFrame to be sure my later operations will be successful.
Can you write Python code for it?


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
I have also concatenated both houses' results into one stack for potential ease of graphing later.
Can you write Python code for it?

senatevertstack = pd.concat([senatedem, senategop], axis=0)

housevertstack = pd.concat([housedem, housegop], axis=0)


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
If we look at what is left, we have all the data in one large DataFrame. For the ease of plotting, we will split these up into four groups later (House Democrats, House Republicans, Senate Democrats, and Senate Republicans).
The other bit of cleaning we have to do is to convert the index 'Congress' from the Congressional number (which began with the 1st Congress in 1787) to the AD year date in order to compare economic and political data. To do this I will create a yearconverter program and apply it to the 'Congress' column of my dataframe to modify the column 'Years' to not reflect a date range (as it was originally) but to have one year.
Can you write Python code for it?

yearconverter = lambda x: x*2 + 1787
poldata['Years'] = poldata['Congress'].apply(yearconverter)

poldata.dtypes


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
Next, we can further slice the DataFrame into both chambers, Senate and House.
Can you write Python code for it?

senate = poldata[np.asarray(poldata.Chamber == 'Senate')]

house = poldata[np.asarray(poldata.Chamber == 'House')]


I am working on the file "MBA_S17/170512_PeterMeijer_EconomyAndPolitics.ipynb".
The first task is:
This DataFrame is a good start, but I need to clean it up to not only narrow the date range to our 1950-2015 period, but to also eliminate third parties (Column 4's 'Other') and 'Vacant' seats, and finally to create a more convenient layout for analysis.
First, let's drop all of the results in the 'PartyStatus' column that aren't Republican or Democrat.
Can you write Python code for it?

poldata = poldata[np.asarray(poldata.PartyStatus == 'Republican')  | np.asarray(poldata.PartyStatus == 'Democrat')]


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
2.2 | Data Information
This dataset only includes names based on a number of factors:
- Names are only included for those who registerested for a Social Security card, not a requirement prior to 1937
- Very unique names are not included in the dataset. For each state where there are less than 5 instances of a name, the name is ommitted, for privacy reasons
- Names without a state of birth submitted on Social Security Card Application are ommitted from the dataset
All of these factors mean that the analysis and calculations will be skewed, and will not represent 100% of the US  population.
3 | Data Analysis
There are numerous different ways to break down the data. I was interested in exploring the different combinations below:

Total unique names
Gender breakdown per state
Most popular names over time
Most popular names in most recent year
Interactive heat map with most popular name broken down by state
How my name has ranked over the years

3.1 | Unique Names
To start diving into the data, I decided to start small: how many names are present in the dataset by gender?
Can you write Python code for it?

# unique names by gender
babynamesDF.groupby('Gender').Name.nunique()

# sum quantity of names by gender
print('Number of F names:', babynamesDF.loc[babynamesDF['Gender'] == 'F', 'Quantity'].sum())
print('Number of M names:', babynamesDF.loc[babynamesDF['Gender'] == 'M', 'Quantity'].sum())


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
As can be seen by the graph, more unique names have been given to children as of the 1950s. Despite more men having been born in the past century, it is clear there is a lot more variation in the names given to women than men.
3.2 | Breakdown per State
After looking at the breakdown of names by gender on a national level, I wanted to take a deeper look into the names by state. I decided to break it down by the number of names in each state versus the number of people in each state, both broken down by gender.
Can you write Python code for it?

# bar chart of baby names per year by gender
stategd = babynamesDF.groupby(['State', 'Gender']).Name.nunique()

# move year to column headers
stategd = stategd.unstack(level='Gender')

stategd

fig, ax = plt.subplots(figsize = (15,8))

stategd['F'].plot(ax=ax, color='#ff69b4', kind='bar')
stategd['M'].plot(ax=ax, color='#0000e5', kind='bar')

ax.set_ylabel('Name Quantity')
ax.set_xlabel('State')
ax.set_title('Unique Names Over Time', fontsize=14, loc='center')

# Put the legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
As was seen in the line graph above, on a per state level, there is still a greater variation in the names given to women than men. Every single state has registered more unique names for women than men, with outliers being California, New York, and Texas, some of the most populous states.
3.3 | Most Popular Names Over Time
I also wanted to see, on a national level, what the most popular names of all time have been. For the most popular names of the last century, I also wanted to see how they have ranked over the years.
Can you write Python code for it?

# top 5 names for all time
namesalltime = babynamesDF[["Gender", "Name", "Year", "Quantity"]]                     # extract columns
namesalltime = namesalltime.pivot_table('Quantity', ['Name', 'Gender'], 'Year', fill_value=0)        # move years to column headers
namesalltime = namesalltime.astype(int)
namesalltime['Total'] = namesalltime.sum(axis=1)                                      # sum across years
namesalltime = namesalltime.sort_values(by = "Total", ascending = False)               # sort Total column descending
namesalltime = namesalltime.reset_index()

namesalltime

namessub = babynamesDF[["Name", "Year", "Quantity"]]
namessub = namessub.pivot_table('Quantity', ['Year'], 'Name', fill_value=0)
namessub = namessub.astype(int)

namessub

# line chart of top 5 all time names per year by gender

fig, ax = plt.subplots(2, 1, figsize = (15, 10))

namessub['James'].plot(ax=ax[0], color='red', linewidth=2)
namessub['John'].plot(ax=ax[0], color='orange', linewidth=2)
namessub['Robert'].plot(ax=ax[0], color='green', linewidth=2)
namessub['Michael'].plot(ax=ax[0], color='blue', linewidth=2)
namessub['William'].plot(ax=ax[0], color='purple', linewidth=2)

namessub['Mary'].plot(ax=ax[1], color='red', linewidth=2)
namessub['Patricia'].plot(ax=ax[1], color='orange', linewidth=2)
namessub['Elizabeth'].plot(ax=ax[1], color='green', linewidth=2)
namessub['Jennifer'].plot(ax=ax[1], color='blue', linewidth=2)
namessub['Linda'].plot(ax=ax[1], color='purple', linewidth=2)

fig.subplots_adjust(hspace=.5)

ax[0].set_title('Top Five Male Names')
ax[1].set_title('Top Five Female Names')

ax[0].set_xlabel('Quantity')
ax[1].set_xlabel('Quantity')

ax[0].legend(loc = 'best')
ax[1].legend(loc = 'best')


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
We can see what the top five names were in 2015, the most recent year in the dataset, for men and women:
Women
1. Sophia | 2,942
- Mia | 2,850
- Emma | 2,706
- Olivia | 2,507
- Isabella | 2,388
Men
1. Noah | 2,751
- Jacob | 2,540
- Ethan | 2,467
- Daniel | 2,460
- Matthew | 2,414
Not a single name in the top 5 for the most recent year is part of the most popular names of all time, a clear indication of how there has been greater variety in the names given to both men and women.
3.5 | Most Popular Name Per State
I was also interested in finding the most popular name per state.
Can you write Python code for it?

# heat map with most popular name by state for all time

heatmap = babynamesDF[["State", "Name", "Gender", "Year", "Quantity"]]                 # extract columns
heatmap = heatmap.pivot_table('Quantity', ["State", 'Name', 'Gender'], 'Year')         # move years to column headers
heatmap['Total']  = heatmap.sum(axis=1)                                                # sum across years
heatmapsub = heatmap[["Total"]]
heatmapsub = heatmapsub.reset_index()
heatmapsub = heatmapsub.sort_values(['State', 'Total'], ascending=[True, False])       # sort Total column descending
heatmapsub = heatmapsub.groupby('State').head(1)

heatmapsub

for col in heatmapsub.columns:
    heatmapsub[col] = heatmapsub[col].astype(str)

scl = [[0.0, 'rgb(242,240,247)'],[1.0, 'rgb(84,39,143)']]

heatmapsub['text'] = heatmapsub['State'] + '
' + heatmapsub['Name'] + '
'+ heatmapsub['Total']

data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = heatmapsub['State'],
        z = heatmapsub['Total'].astype(float),
        locationmode = 'USA-states',
        text = heatmapsub['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Top Name per State")
        ) ]

layout = dict(
        title = 'Top Name per State',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )
iplot(go.Figure(data=data, layout=layout), link_text="")


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
While the popular names for men have remained popular, there has been great variation in the names gien to women. Despite these five names being the most popular over the past century, there is a clear peak for each and decline, clearly seen by the female names. The top five names for each gender were:
Men
1. James | 97,091
- John | 94,862
- Robert | 92,462
- Michael | 84,950
- William | 75,346
Women
1. Mary | 73,221
- Patricia | 30,975
- Elizabeth | 29,655
- Jennifer | 28,883
- Linda | 28,829
3.4 | Most Popular Names in 2015
I also wanted to check the most popular names in the dataset for the most recent year.
Can you write Python code for it?

# most popular names for most recent year
nameyr = babynamesDF[["Gender","Name","Year","Quantity"]]
yrvariable = [2015]
nameyr = nameyr[nameyr['Year'].isin(yrvariable)].set_index('Name').sort_values(by='Quantity', ascending=False)
nameyr


I am working on the file "MBA_S17/BabyNames-Persegani.ipynb".
The first task is:
With the exception of one state (New Mexico - Mary), all other states had a male name as the most popular name, which was one of the most popular names over the last century: James, John, Robert, Michael, or William.
3.6 | How My Name Has Ranked Over the Years
Lastly, given my name is not a very traditional American name (Natalia), I was interested to see if it was present in the dataset for every year. I was surprised to find that there were far more Natalias in the last century than I'd expected.
Can you write Python code for it?

# how my name has ranked over time
natalia = babynamesDF[["Name", "State", "Year", "Quantity"]]                # extract columns
natalia = natalia.pivot_table('Quantity', ['Name', "Year"], 'State', fill_value=0)       # move years to column headers
natalia = natalia.astype(int)
natalia['Total']  = natalia.sum(axis=1)                                                # sum across years
natalia = natalia[["Total"]]
natalia = natalia.reset_index()
natalia = natalia.set_index("Name").loc["Natalia"]
natalia = natalia.reset_index()
natalia = natalia.set_index("Year")

natalia

fig, ax = plt.subplots(figsize = (15,30))

natalia['Total'].plot(ax=ax, color='#ff69b4', kind='barh')

ax.set_ylabel('Year')
ax.set_xlabel('Quantity')
ax.set_title('Number of Natalias', fontsize=14, loc='left')

birthyr = natalia.index.tolist().index(1988)
ax.get_children()[birthyr].set_color('blue')


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
3.1.2 | Leisure Activity Data

Fetched data from BLS website to further understand what leisure activities are most popular among Americans
Cleaned the text file in order to accommodate the missing and multiple delimiters
Handled the gap with numeric data to ensure data consistency
Can you write Python code for it?

# Fetching Data for Leisure activity (will be used further down in the analysis)

dls = "https://www.bls.gov/tus/charts/chart9.txt"
resp = requests.get(dls)
with open('chart9.txt', 'wb') as output:
    c = output.write(resp.content)

# Extracting the text file data

lines = open("chart9.txt").readlines()
open('newfile.txt', 'w').writelines(lines[2:-4])
f_leisure = open("newfile.txt","r")
data_leisure = f_leisure.read()

# Replace the target string to fix the delimiters

data_leisure = data_leisure.replace("\t", '|').replace("||||", '|').replace("|||", '|').replace("||", '|')

# Write the file out again

with open('newfile.txt', 'w') as file:
    file.write(data_leisure)

f_leisure = open("newfile.txt","r")
data_leisure = f_leisure.read()

# Extracting/Cleaning the data and renaming certain columns

df_leisure_all = pd.read_csv(open("newfile.txt","r"), delimiter="|")
df_leisure_all = df_leisure_all.rename(columns={'Unnamed: 0': 'Activity_Leisure_SubActivity'})
df_leisure_all = df_leisure_all.drop(df_leisure_all.index[[7]])
df_leisure_all.iloc[0, df_leisure_all.columns.get_loc('Minutes')] = 167
df_leisure_all
df_leisure_all = df_leisure_all.set_index(['Activity_Leisure_SubActivity'])

df_leisure_all= df_leisure_all.astype(float)
df_leisure_all


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
3.1.3 | Age Level Activity Data

Fetched data from BLS website to further understand the time indulged in activities based on Age
Age Brackets considered are:
Ages 15-49
Ages 55-64
Ages 65-74
Ages 75 +

Cleaned the text file in order to accommodate the missing and multiple delimiters
Handled the gap with numeric data to ensure data consistency
Can you write Python code for it?

# Fetching Students Data (will be used further down in the analysis)

dls = "https://www.bls.gov/tus/charts/chart6.txt"
resp = requests.get(dls)
with open('chart6.txt', 'wb') as output:
    c = output.write(resp.content)

# Extracting the text file data

lines = open("chart6.txt").readlines()
open('newfile.txt', 'w').writelines(lines[1:-5])
f_s = open("newfile.txt","r")
data_s = f_s.read()

# Replace the target string to fix the delimiters

data_s = data_s.replace("\t", '|').replace("||||", '|').replace("|||", '|').replace("||", '|').replace("activities", 'Working').replace("Educational Working", 'Household/Educational Activities')

# Write the file out again

with open('newfile.txt', 'w') as file:
    file.write(data_s)

f_s = open("newfile.txt","r")
data_s = f_s.read()

# Extracting the data and renaming certain columns

df_students = pd.read_csv(open("newfile.txt","r"), delimiter="|")
df_students = df_students.drop(df_students.index[[3,9,5,6,7,8]])
df_students = df_students.rename(columns={'Unnamed: 0': 'Main_Activity', 'Hours': 'Ages 15-49'})
df_students['Main_Activity'] = df_students['Main_Activity'].str.strip()
df_students = df_students.set_index(['Main_Activity'])
df_students

# Fetching Elders Data (will be used further down in the analysis)

dls = "https://www.bls.gov/tus/charts/chart4.txt"
resp = requests.get(dls)
with open('chart4.txt', 'wb') as output:
    c = output.write(resp.content)

# Extracting the text file data

lines = open("chart4.txt").readlines()
open('newfile.txt', 'w').writelines(lines[4:-4])
f_e = open("newfile.txt","r")
data_e = f_e.read()

# Replace the target string to fix the delimiters

data_e = data_e.replace("\t", '|').replace("||||", '|').replace("|||", '|').replace("||", '|').replace("Household activities", 'Household/Educational Activities')

# Write the file out again

with open('newfile.txt', 'w') as file:
    file.write(data_e)

f_e =...


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
3.2 | Cleaning and Organizing Data

Cleaned the Activity data to ensure no outliers are present i.e. negative values, consistent decimal places, substitution of missing values
Feature engineered additional data fields to observe distinct trends
Merged multiple datasets in order to obtain a well-rounded view
Can you write Python code for it?

# Cleaning the data and computing average time spent on activities at gender level

# Main Activity

df_main_final= df_main_final.apply(pd.to_numeric, errors='ignore')
df_main_final["AvgHrsMenMain"]= df_main_final[['AvgHrsMen_2011','AvgHrsMen_2012','AvgHrsMen_2013','AvgHrsMen_2014','AvgHrsMen_2015']].mean(axis = 1)
df_main_final["AvgHrsWomenMain"]= df_main_final[['AvgHrsWomen_2011','AvgHrsWomen_2012','AvgHrsWomen_2013','AvgHrsWomen_2014','AvgHrsWomen_2015']].mean(axis =1)
df_main_final = df_main_final.round(2)
df_main_final

# Cleaning the data and computing average time spent on activities at gender level

# Sub-Activity

df_sub_final=df_sub_final.replace('\(','',regex=True).replace('\)','',regex=True)
df_sub_final= df_sub_final.apply(pd.to_numeric, errors='ignore')
df_sub_final["AvgHrsMenSub"]=df_sub_final[['AvgHrsMen_2011','AvgHrsMen_2012','AvgHrsMen_2013','AvgHrsMen_2014','AvgHrsMen_2015']].mean(axis =1)
df_sub_final["AvgHrsWomenSub"]=df_sub_final[['AvgHrsWomen_2011','AvgHrsWomen_2012','AvgHrsWomen_2013','AvgHrsWomen_2014','AvgHrsWomen_2015']].mean(axis =1)
df_sub_final = df_sub_final.round(2)
df_sub_final

# Sorting the dataframes as per the hours spent

df_main_final = df_main_final.sort_values('AvgHrsMenMain', ascending=True)

# Re-setting the Index

df_main_final = df_main_final.reset_index()
df_sub_final = df_sub_final.reset_index()

# Trimming the data to format the dataframe

df_main_final['Main_Activity'] = df_main_final['Main_Activity'].str.strip()
df_sub_final['Sub_Activity'] = df_sub_final['Sub_Activity'].str.strip()

# Combining the Students and Elderly dataframes to obtain a consolidated dataframe

df_age_data = pd.concat([df_students,df_elderly], axis = 1)
df_age_data = df_age_data.reset_index()
df_age_data = df_age_data.rename(columns={'index': 'Main_Activity'})
df_age_data = df_age_data.set_index('Main_Activity')
df_age_data


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
4.5 | Deep-Diving and visualizing data at sub-activity level for the top 4 main activities
From all of the above visualizations, we can concretely see that few of the primary activities really stand out. Knowing this, we wanted to further delve into the data to decipher which sub-activities (within the above mentioned top 4 main activities) do Americans perform most. This granular analysis of the data will provide a deeper insight to more locally target the relevant customer base.
We created main activity level segments to organize so that we can correlate easily.
Can you write Python code for it?

# Filtering out the sub-activities of the Top 4 main activities

top_list = ['Sleeping', 'Grooming', 'Health-related self care', 'Personal activities', 'Travel related to personal care', 'Working',
            'Work-related activities', 'Other income-generating activities', 'Job search and interviewing', 'Travel related to work',
            'Attending class', 'Homework and research', 'Travel related to education', 'Socializing, relaxing, and leisure',
            'Sports, exercise, and recreation', 'Travel related to leisure and sports']

df_sub_final_u = df_sub_final[df_sub_final['Sub_Activity'].isin(top_list)]
df_sub_final_u = df_sub_final_u.reset_index()

# Merging the sub-activity data with main activity to create categories/segements

data = {'Main_Activity': ['Personal care activities', 'Personal care activities', 'Personal care activities','Personal care activities','Personal care activities', 'Working and work-related activities', 'Working and work-related activities','Working and work-related activities', 'Working and work-related activities', 'Working and work-related activities',
'Educational activities', 'Educational activities', 'Educational activities', 'Leisure and sports', 'Leisure and sports', 'Leisure and sports']}
df_main_act = pd.DataFrame(data)

df_sub_final_q = pd.merge(df_sub_final_u, df_main_act, left_index=True, right_index=True)
df_sub_final_q.drop('index', axis=1, inplace=True)

# Cleaning and sorting the data

df_sub_final_Personal_Care = df_sub_final_q.groupby(['Main_Activity']).get_group('Personal care activities')
df_sub_final_Personal_Care = df_sub_final_Personal_Care.set_index(['Sub_Activity'])
df_sub_final_Personal_Care = df_sub_final_Personal_Care.sort_values('AvgHrsMenSub', ascending=False)

df_sub_final_Educational = df_sub_final_q.groupby(['Main_Activity']).get_group('Educational activities')
df_sub_final_Educational = df_sub_final_Educational.set_index(['Sub_Activity'])
df_sub_final_Educational = df_sub_final_Educational.sort_values('AvgHrsMenSub',...


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
4.7 | Visualizing time spent on Sports & Leisure activities at a geographic level
 From the below geographic distribution, we see the regions within United States of America with maximum interest in sports related activities

Northern USA is more inclined towards sports activities with Alaska, Montana, and Wyoming leading the race
Southern USA is not very active in this particular domain
Can you write Python code for it?

# Geographic Distribution of Sports and Leisure Activities

for col in df_geo_sports.columns:
    df_geo_sports[col] = df_geo_sports[col].astype(str)
#shows color gradient as hours increases
scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
       [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]

df_geo_sports['text'] = df_geo_sports['State']
layout = dict(
        title = 'Average Time spent on Sports & Leisure (in hours) <br>(Hover for breakdown)',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )
data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df_geo_sports['code'],                      # picks 2 digit state code from csv
        z = df_geo_sports['Hours'].astype(float),               # picks activity hrs as float
        locationmode = 'USA-states',
        text = df_geo_sports['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Time in Hours")
        ) ]
fig = dict( data=data, layout=layout )
py.iplot( fig, filename='d3-cloropleth-map' )


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
4.8 | Ad-Hoc Analysis: Time spent on Organizational, Civic, and Religious activities at a geographic level
 We were curious to see if religion and the corresponding activities are very popular among Americans.
We notice that religion is more strictly adhered to in the south-eastern part of the country. According to this ad-hoc analysis, the type of mentality and mind-set can also be worked into developing lucrative business strategies.
Can you write Python code for it?

# Geographic Distribution of Religious and Civic Organization Activities

for col in df_geo_religion.columns:
    df_geo_religion[col] = df_geo_religion[col].astype(str)
#shows color gradient as hours increases
scl = [[0.0, 'rgb(243,205,174)'],[0.3, 'rgb(237,184,140)'],[0.6, 'rgb(227,142,72)'],\
            [0.9, 'rgb(72,39,11)'],[1.0, 'rgb(38,20,6)']]

df_geo_religion['text'] = df_geo_religion['State']
layout = dict(
        title = 'Average time spent on Organizational, Civic & Religious Activities (in hours) <br>(Hover for breakdown)',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )
data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df_geo_religion['code'],               # picks 2digit state code from csv
        z = df_geo_religion['Hours'].astype(float),        # picks activity hrs as float
        locationmode = 'USA-states',
        text = df_geo_religion['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Time in Hours")
        ) ]
fig = dict( data=data, layout=layout )
py.iplot( fig, filename='d3-cloropleth-map' )


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
From the visualization above, we see that majority of the Americans (both genders) tend to spend most time on the following activities on an average:

Personal Care Activities
Working and Work related Activities
Educational Activities
Leisure and Sports

As the above visualization provides an idea regarding the top activities, we wanted to see this at a yearly level to further highlight the significance of these activities. By understanding the trends over the years, we can forecast as to which activities will pose relevance in future as well.
4.2 | Visualizing trends for main activities through years 2011-2015
We can see the fluctuations in average hours per activity through each year from 2011 to 2015 for men and women. It is important to note these changes in trends to channelize advertisements/promotions in the right category for maximized results in the future as well (aiming for forecasting predictions).
Can you write Python code for it?

# Plotting the view for main activities at yearly level

df_men = df_main_final.filter(regex="Men+",axis=1)
df_women = df_main_final.filter(regex="Women+",axis=1)
fig, ax = plt.subplots(nrows=1,ncols=2,figsize=(8,8))

# Creating a loop so that yearly data can be mapped

i = 0
for Activity in list(df_men.index):
    ax[0].plot(df_men.loc[Activity].tolist()[:-1],"ko",markersize=5)
    ax[0].plot(df_men.loc[Activity].tolist()[:-1],linestyle='dashed',label=Activity,color=colors[i+1])
    ax[1].plot(df_women.loc[Activity].tolist()[:-1],"ko",markersize=5)
    ax[1].plot(df_women.loc[Activity].tolist()[:-1],linestyle='dashed',label=Activity,color=colors[i+1])
    if i>=9:
        i=0
    else:
        i+=1
ax[0].legend(loc="upper left", fontsize=10,framealpha=0.2,bbox_to_anchor=(2.5, 1))
fig.subplots_adjust(wspace=0.3, hspace=0)
ax[0].set_title("Year level Main Activity trends (Men)")
ax[1].set_title("Year level Main Activity trends (Women)")

ax[0].set_xticks(list(range(0,5)))
ax[0].set_xticklabels(list(range(2011,2016)))
ax[1].set_xticks(list(range(0,5)))
ax[1].set_xticklabels(list(range(2011,2016)))

xaxis1 = ax[0].get_xaxis()
xaxis2 = ax[1].get_xaxis()

for ticks1,ticks2 in zip(xaxis1.get_ticklabels(),xaxis2.get_ticklabels()):
    ticks1.set_rotation(45)
    ticks1.set_color('k')
    ticks2.set_rotation(45)
    ticks2.set_color('k')

plt.show()


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
We observe from the yearly trends that -
+ Time spent by both the genders has been gradually increasing from 2011 to 2015. This illustrates that a large emphasis is placed by individuals on personal care.
+ Trends corresponding to Educational activities show a dip in the year 2014 for both genders but it is seen that it is slowly picking up in the year 2015.
+ Overall, non-top 4 activities are consistent among their yearly trends which basically inidicates that higher emphasis on the same may not be extremely beneficial.
4.3 | Which activity is the primary focus for each gender?
 From the below visualization we see the Gender breakdown for some of the key primary activities.
This further provides an idea about which activity is of higher focus for each gender so that gender-localized targeting strategy can be developed.

We clearly notice that though relatively the amount of time spent is in almost the same bracket for most of the activities, women tend to invest more time in house-hold activities.
Men tend to spend more time indulging in leisure activities
The derivations above correlates with the normal convention of gender norms as well. Though we are seeing both genders involved in work related activies too, this disparity of activities is still distinct.
Can you write Python code for it?

# Creating the visualization to distinctly identify important activies for each gender

fig, ax = plt.subplots(nrows=1,ncols=2, figsize=(6,6))
locx = list(range(0,10))
barwidth = 0.35
for loc, Activity in zip(range(len(df_men)),list(df_men.index)):
    bar1, = ax[0].barh(loc,round(df_men.loc[Activity]["AvgHrsMenMain"],2),label=Activity,color = colors[loc+1])
    ax[0].text(bar1.get_width()+1.5,bar1.get_y()+barwidth/2,bar1.get_width(),ha='left', va='bottom')
    bar2, = ax[1].barh(loc,round(df_women.loc[Activity]["AvgHrsWomenMain"],2),label=Activity,color = colors[loc+1])
    ax[1].text(bar2.get_width()*1.05,bar2.get_y()+barwidth/2,bar2.get_width())
ax[0].set_xticks([])
ax[0].set_yticks([])
ax[1].set_xticks([])
ax[1].set_yticks([])
ax[0].spines['top'].set_visible(False)
ax[0].spines['left'].set_visible(False)
ax[0].spines['bottom'].set_visible(False)
ax[0].spines['right'].set_visible(False)
ax[1].spines['top'].set_visible(False)
ax[1].spines['right'].set_visible(False)
ax[1].spines['bottom'].set_visible(False)

ax[0].invert_xaxis()                        #this invert provides the opposite comparison graphs between genders
ax[0].set_title("Average Hours for Men")
ax[1].set_title("Average Hours for Women")
box1 = ax[0].get_position()
box2 = ax[1].get_position()
fig.subplots_adjust(wspace=0.01, hspace=0)
l = ax[1].legend(loc="lower right", fontsize=10,framealpha=0.6, markerscale=5,labelspacing=0.1,borderpad=0.1
                 ,bbox_to_anchor=(2.2, -.1))
plt.show()


I am working on the file "MBA_S17/Boddu-Jadwani-Kutty-American_Time_Use_Study.ipynb".
The first task is:
We see that majority of the time is spent on either sleeping or working followed by attending class (target student crowd) or socializing, relaxing, and leisure.
All of these activities provide a profitable platform to advertise for a certain segment of population and develop a sales strategy.

For instance, since Americans spend an ample amount of time sleeping/resting or working, this could be leveraged such that the potential customer base is rightfully tapped based on the product.

Likewise, products catering to students and teens can be branded and publicized in and around academic and college campuses to generate maximum revenue.

As we see from the plot above, socializing, relaxing, and leisure is also a primary activity with potential for convenient targeting. We wanted to further look into this category to clearly pin-point the modes by which advertising would be most effective.
4.6 | Leisure Activity Breakdown
From the below pie chart, we see that most of the time is consumed in:
+ Watching TV
+ Socializing and Communicating
+ Playing Games; Using Computer for Leisure
+ Sports, exercise, and recreation
With the above insight into the type of leisure activities, we see that TV and Internet could pose to be very strategic platforms for exploiting a potential audience.
Can you write Python code for it?

# Creating the exploded pie chart

fig, ax = plt.subplots(figsize=(8, 8))
explode = [0,0.1,0.2,.4,0.3,0.5,0.6]
color = [colors[x] for x in list(range(1,len(df_leisure_all["Minutes"])+1))]
p,t = ax.pie(list(df_leisure_all["Minutes"]), explode=explode,shadow=True, startangle=90, radius=1.3,colors=color)
labels = ['{0} - {1:1.2f}'.format(i,j) for i,j in zip(list(df_leisure_all.index), list(df_leisure_all["Minutes"]))]
box1 = ax.get_position()
ax.set_position([box1.x0, box1.y0, box1.width * 0.9, box1.height])
l = ax.legend(p,labels , loc="upper right", fontsize=12,framealpha=0.2,bbox_to_anchor=(1.8, 1))
l.get_title().set_position((30, 0))

# Equal aspect ratio ensures that pie is drawn as a circle

ax.axis('equal')
ax.set_title("AVERAGE TIME SPENT BY AMERICANS IN LEISURE ACTIVITY (IN MINUTES)",fontsize=15)
plt.show()


I am working on the file "MBA_S17/Capucilli-Trentham-Stone-TheBachelor.ipynb".
The first task is:
Here, we can see that ages 26 and 27 dominate the elimination age for the first few weeks. This is interesting because it might suggest that the bachelor is interested in a polarized age demographic at first. He seems to be ruling out much of the middle ground. That said, it could also be the case that the bachelor is keeping only the contestants in the polarized age demographic, but that their average ages are 26 and 27.
In the middle weeks, the younger contestants seem to be targeted more for elimination. We think a major takeaway here is that the Bachelor may be becoming more serious about the process as he is moving along, and thus is elimnating more immature contestants (contestants not yet ready for marriage).
We'll now look at the same information using the male contestant dataframe (Sheet 3):
Can you write Python code for it?

df3_clean = df3.set_index('Season')

df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Episode', 'Week')
df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Eliminated in episode', 'Week')
df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Removed in episode', 'Week')
df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Quit in episode', 'Week')
df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Withdrew in episode', 'Week')
df3_clean['Eliminated']=df3_clean['Eliminated'].str.replace('Runner-up', 'Week Runner-up')

AgeWeekM = df3_clean[['Age', 'Eliminated']]
AgeWeekM = AgeWeekM.groupby('Eliminated')
AgeWeekM = AgeWeekM.mean()
AgeWeekM.plot(linewidth=3, color = 'black', title='Average Age by Year (Men)')

AgeWeekM.plot(kind='bar', ylim=[24,32], color = 'dodgerblue', title='Average Age by Week Eliminated (Men)')


I am working on the file "MBA_S17/Capucilli-Trentham-Stone-TheBachelor.ipynb".
The first task is:
Looks like we have more cleaning to do. We'll use the following code to make our x-axis more consistent:
Can you write Python code for it?

df2_clean = df2

df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Withdrew in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Eliminated in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Quit in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Left in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Disqualified in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Removed in episode', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Quit in epiosde', 'Week')
df2_clean['Eliminated'] = df2_clean['Eliminated'].str.replace('Runner-up', 'Week Runner-Up')

AgeWeekF = df2_clean[['Age', 'Eliminated']]
AgeWeekF = AgeWeekF.groupby('Eliminated')
AgeWeekF = AgeWeekF.mean()

AgeWeekF.plot(kind='bar', ylim=[24,32], color = 'deeppink', title="Average Age by Elimination Week (Women)")


I am working on the file "MBA_S17/Capucilli-Trentham-Stone-TheBachelor.ipynb".
The first task is:
The biggest takeaway here is that the ages of contestents are far younger for women than men in general. Other than the average age being significantly different, the two charts show surprisingly similar patterns. The fluctuations are oddly identical. There is most likely some sort of social psychology trend at play here.
III. Proposals and Marriages
We will now look at the end results of both the Bachelor and the Bachelorette. How many seasons result in a proposal? Are those engagements likely to result in marriage or in a break-up after the show ends? Is there any difference between bachelor and bachelorette seasons?
Can you write Python code for it?

df_proposal = df[['Proposal', 'Show']]
df_proposal.head(2)

df_proposal = df_proposal.groupby(['Show', 'Proposal']).size()
df_proposal = df_proposal.unstack()

df_proposal.plot(kind='barh', color = ['silver', 'limegreen'], title='Did the season result in a proposal?')


I am working on the file "MBA_S17/Capucilli-Trentham-Stone-TheBachelor.ipynb".
The first task is:
The key point gathered here is that the men (or bachelors) are far less likely to propose at the end of a season. We think that much of this has to do with their overall intent when beginning the process of applying for the show. Perhaps the women genuinely want to get engaged and the men seem more keen on becoming a TV personality. There is much discussion during the show about whether or not contestents are there for the "right reasons". Given the chart above, we might assume that more women are there for the right reasons than men, though it of course could be the case that the bachelors did not make a connection with their contestents with greater frequency than the bachelorettes with their contestents.
Can you write Python code for it?

df_marriage = df[['Success', 'Show']]
df_marriage = df_marriage.groupby(['Show', 'Success']).size()
df_marriage = df_marriage.unstack()

df_marriage.plot(kind='barh', color=['silver', 'plum'], title='Did the season result in marriage?')


I am working on the file "MBA_S17/Capucilli-Trentham-Stone-TheBachelor.ipynb".
The first task is:
This chart is pretty illuminating. It illustrates that the Bachelorette women are far more succesful in choosing a partner. Of the 9 proposals on the Bachelorette, 3 resulted in marriage. Of the 10 proposals on the Bachelor, only 2 have resulted in marriage. Again, this could be related to the fact that the women who enter onto the show are far more dedicated to finding love and a life partner.
IV. Occupations
Finally, we'll take a look at the occupations of female and male contestants:
Can you write Python code for it?

OccM = df3[['Occupation']]
OccM = OccM.groupby(['Occupation']).size()
OccM = pd.DataFrame(OccM)

OccM.columns = ['Count']
OccM = OccM[OccM.Count !=1]
OccM.plot(kind ='bar', color ='dodgerblue', title='Frequency of Occupations, Male Contestants (>1)')


I am working on the file "MBA_S17/Gitan-Syrian-Refugee-Resettlement.ipynb".
The first task is:
3. THE MAJORITY OF SYRIAN REFUGEES SETTLE IN URBAN AREAS
San Diego, Chicago, and Troy have resettled the most Syrian refugees -- almost 13%. No Syrian refugees have resettled in Alabama, Alaska, Hawaii, Mississippi, and Wyoming. Montana, North Dakota, South Dakota, Vermont, and West Virginia have resettled less than ten Syrian refugees each. The majority of Syrian refugees resettled in Midwestern states (27.95%).
4. REFUGEES IMPACT COMMUNITIES
Refugees help create jobs, raise wages and boost the economy overall – paying back the upfront costs associated with resettlement. Refugees revive small towns and cities from Vermont and New York, to Pennsylvania and Michigan by becoming active members in their communities.
Can you write Python code for it?

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Bar(
    x=['California', 'Michigan', 'Texas', 'Pennsylvania', 'Arizona', 'Illinois', 'Florida', 'New York', 'Ohio', 'North Carolina'],
    y=[2260, 2168, 1547, 1267, 1252, 1203, 1112, 1042, 906, 895],
    text=['11.01% Share', '10.56% Share', '7.53% Share', '6.17% Share', '6.09% Share', '5.86% Share', '5.41% Share', '5.07% Share', '4.41% Share', '4.36% Share'],
    marker=dict(
        color='rgb(89,43,140)',
        line=dict(
            color='rgb(89,43,140)',
            width=1.5,
        )
    ),
    opacity=0.8
)

data = [trace0]
layout = go.Layout(
    title='Syrian Refugee Arrivals by State, March 2011 - April 2017'
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='text-hover-bar')


I am working on the file "MBA_S17/Gitan-Syrian-Refugee-Resettlement.ipynb".
The first task is:
4. Resettlement Facts
1. THE U.S. HAS RESETTLED 20,525 SYRIAN REFUGES SINCE MARCH 2011
The majority of Syrian refugees settled in a single year was 15,479 in 2016 after the Obama administration’s commitment to resettle 10,000 Syrian refugees. In the first five years of the Syrian civil war between 2011 to 2015, only 2,547 Syrian refugees resettled in the U.S.
2. SYRIAN REFUGEES ACCOUNT FOR ONLY 4.81% OF ALL RESETTLED REFUGEES FROM MARCH 2011 – APRIL
The five highest refugee sending nations include Burma (20.95% or 89,300), Iraq (19.62% or 83,635), Bhutan (13.03% or 55,568), Somalia (10.95% or 46,701), and the Democratic Republic of Congo (9.61% or 40,998).
Can you write Python code for it?

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Bar(
    x=['2011', '2012', '2013', '2014', '2015', '2016', '2017'],
    y=[40904, 66251, 59817, 70628, 64325, 81395, 14244],
    name='Other Refugees',
    marker=dict(
        color='rgb(89,43,140)'
    )
)
trace1 = go.Bar(
    x=['2011', '2012', '2013', '2014', '2015', '2016', '2017'],
    y=[20, 41, 45, 249, 2192, 15479, 2499],
    name='Syrian Refugees',
    marker=dict(
        color='rgb(163,166,168)',
    )
)

data = [trace0, trace1]
layout = go.Layout(
    title='Refugee Arrivals, March 2011 - April 2017',
    xaxis=dict(tickangle=-45),
    barmode='group',
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='angled-text-bar')


I am working on the file "MBA_S17/Gitan-Syrian-Refugee-Resettlement.ipynb".
The first task is:
The Syrian refugee crisis has been called one of the greatest humanitarian crisis since World War II. Half of the population – 11 million Syrians – have been killed or forced to flee. More than 200,000 Syrians have died. 6.3 million Syrians have been internally displaced, and 5 million Syrians have fled – the combined populations of California, New York and Florida. 4 out of 5 Syrians live in poverty and the life expectancy has dropped by 20 years. School attendance has dropped over 50 percent, with more than 2 million children now out of school.
In addition to resettlement, the international community has responded to the crisis by providing aid. Syrian refugees have received record aid, including 6 billion USD in 2016 at the London Syria Conference – the highest raised in a single day for a single cause by the United Nations High Commissioner for Refugees (UNHCR). Despite fundraising efforts, the UNHCR requires nearly 2 billion USD in 2017 for the Middle East and North Africa. The US has contributed 6.5 billion USD in aid since the beginning of the crisis, including 3.3 billion USD for aid inside Syria.
U.S. Resettlement Factors
Many factors limit refugee resettlement to the U.S., including wavering political commitment from the White House between Obama and Trump administrations. The Obama administration committed to resettle 10,000 refugees in September 2015 -- a goal surpassed. On the other hand, the Trump administration signed two executive orders to ban Syrian refugees -- both orders were blocked by federal courts.
But the U.S. refugee resettlement process is also a major factor. Unlike Europe, the U.S. admits refugees into the country only after processing. Europe processes refugees once they arrive on European soil. In the U.S., Refugees undergo an ‘extreme’ vetting process that can take more than two years. They go through multiple agency background checks, finger print screenings, reviews, and interviews. It is a difficult process to resettle in the U.S. as a refugee.

U.S. Resettlement
Since...
Can you write Python code for it?

import plotly.plotly as py
import pandas as pd

df = pd.read_csv('https://ionutgitan.com/s/Gitan_Data_State.csv')

for col in df.columns:
    df[col] = df[col].astype(str)

scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(191,174,211)'],[0.4, 'rgb(165,142,193)'],\
            [0.6, 'rgb(140,109,176)'],[0.8, 'rgb(114,76,158)'],[1.0, 'rgb(89,43,140)']]

df['text'] = df['state'] + '<br>' +\
    'Total Refugees '+df['total refugees']

data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df['code'],
        z = df['total refugees'].astype(float),
        locationmode = 'USA-states',
        text = df['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Refugee Population")
        ) ]

layout = dict(
        title = 'Syrian Refugee Arrivals by State, March 2011 - April 2017',
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )

fig = dict( data=data, layout=layout )
py.iplot( fig, filename='d3-cloropleth-map' )


I am working on the file "MBA_S17/GroupProject_v4.ipynb".
The first task is:
1 | Background
Designed by Eugene Fama and Kenneth French, Fama-French factor model is a widely used tool in finance created by employing statistical techniques to estimate returns of stocks. Within this project, we attempted to analyze stock returns and risks by calculating betas of different industries over the past seven year period.
Source: Fama-French Website
2 | About the Data
We collected our data by using PANDAS DataReader to get a direct feed to Kenneth French's data, where numerous equity market data are available online. Among them, we used the "30 Industry Portfolio" dataset to compare stock returns and risks of different industries.
Links to  data:
+ 30 Industry Portfolio
+ Documentation to get direct feed from DataReader
3 | Key Data
We first imported the 30 industry portfolio data set. There are different categories: value or equal weighted, monthly or annual, etc. Detailed breakdown and description are shown below.
3.1 | Slicing the Key Data
Among many different types of data, we will extract value-weighted monthly return (dataframe: 0 in 30 Industry Portfolios) since 2010 to run our analysis and store it in a dataframe ind.
We also imported Fama-French 3-factor data with the same time frame, which contain:

Mkt-RF (market return - risk free rate)
SMB (Small-Minus-Big, the average return on the three small portfolios minus the average return on the three big portfolios)
HML (High-Minus-Low,  the average return on the two value portfolios minus the average return on the two growth portfolios)

Because we need market return rather than equity risk premium we add "Mkt" column in the dataframe by combining "Mkt-RF" and "RF". Finally, we set this 3-factor market data (Mkt-RF, SMB, HML, RF, and Mkt) in dataframe mkt1.
Can you write Python code for it?

# importing 30 industry portfolio data set
import pandas_datareader.data as web

ff=web.DataReader("30_Industry_Portfolios", "famafrench")

print(ff['DESCR'])

# extracting value-weighted return only
ff[0]

ind=ff[0]

ind.shape

# importing mkt data from 3 factors model

mkt=web.DataReader("F-F_Research_Data_Factors", "famafrench")

mkt

print(mkt['DESCR'])

# Dropping annual result
mkt1=mkt[0]

mkt1

mkt1['Mkt']=mkt1['Mkt-RF']+mkt1['RF']


I am working on the file "MBA_S17/GroupProject_v4.ipynb".
The first task is:
4 | Beta Calculation
In order to facilitate matrix calculation, we altered the form of ind_stat to a inverse matrix and stored it as ind_stat_inv.
By definition, industry betas are calculated as:
Beta = (covariance between market and an industry) / (variance of market)
Once we found industry betas, we created a new column "Beta" to our ind_stat_inv and sorted by beta in ascending order.
Can you write Python code for it?

# inverse matrix
ind_stat_inv = pd.DataFrame(np.linalg.pinv(ind_stat.values), ind_stat.columns, ind_stat.index)
ind_stat_inv

# beta calculation

def calc_beta(n):
    np_array = ind.values
    m = np_array[:,30] # market returns are column zero from numpy array
    s = np_array[:,n] # stock returns are column one from numpy array
    covariance = np.cov(s,m) # Calculate covariance between stock and market
    beta = covariance[0,1]/covariance[1,1]
    beta = covariance[0,1]/covariance[1,1]
    return beta

numlist=range(0,31,1)

beta=[calc_beta(i) for i in numlist]
beta

# Adding beta result
ind_stat_inv['Beta']=beta
ind_stat_inv

sort=ind_stat_inv = ind_stat_inv.sort_values(by='Beta', ascending=False)
sort


I am working on the file "MBA_S17/GroupProject_v4.ipynb".
The first task is:
On the heatmap of monthly returns by industry, we can see which industries have more extreme swings, and which have less variation. 'Coal' looks to be particularly volatile. 'Food' and 'Utilities' looks more stable.
Can you write Python code for it?

#Sort a beta-only table to create beta bar chart
beta_table = sort[['Beta']]
beta_table.head()

#Bar chart of betas sorted from high to low
plt.style.use('seaborn-pastel')

ax = beta_table.plot(kind='bar', colormap = "Pastel2")
ax.set_title("Betas Across Industries")


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
As explained by the graph above, the inflation fluctuates and shows a lot of variability. In 1990, we have the inflation coming down from having been very high in the late 80´s in part do to increased oil prices and the decision made by the US to abandon the gold standard. That being said, the factors influencing inflation and the reason for its behaviour are out of the scope of this project. The graph also shows a rise in the early 2000´s (housing boom in Iceland) and then again in 2008 subsequently after the most recent financial crisis.
This eradic behaviour and instability has led to the introduction of inflation indexation as a means to mitigate the effects of these constant fluctuations.
Can you write Python code for it?

# Inflation summary statistics

inflationStatistics = inflation.describe([.25, .50, .75, .95])
inflationStatistics

# Calculating the Upper and Lower Specification limits by using a deviation of 3 sigma

USL = inflationStatistics.T['mean'] + 3 * inflationStatistics.T['std']
LSL = inflationStatistics.T['mean'] - 3 * inflationStatistics.T['std']
print ('The Upper Specification limit is', USL,
       'and the Lower Specification Limit is', LSL)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
From the table above, we focus on 4 measures, mean, standard deviation, min and max.
First, lets compare the 2 equal payment loans. The max and min payment for both options are similar but looking at the average (mean) payments and their standard deviation we can see that the non-indexed one is a better option with a slightly lower average payment and less variability, explained by a lower standard deviation. The max payments are very similar
Second, lets compare the 2 equal principal payment loan options. The indexed option has a lower max payment, a much lower standard deviation but a slightly higher average monthly payment. Deciding between the two here, is not as straight forward. It depends on favoring lower average payments to lower variability or vice versa.
Can you write Python code for it?

# Calculating the sum of payments throughout the loan period and plotting a bar chart.

totalPayments = equalMonthlyTotalPayments.sum()
fig11, ax = plt.subplots(figsize = (14, 7))

totalPayments.plot(kind='barh', ax=ax, width = 0.3, color = 'r')
ax.tick_params(labelsize = 15)
ax.set_xlabel('Sum of Payments (isk)', size = 20)
fig11.suptitle('Total Payments - End of Period', size = 15)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
Non-Indexed
Can you write Python code for it?

# Setting the parameters and executing the required manipulation

interest = ratePeriod['Non-Indexed AVG']

# Setting up the payment plan (Actual and Projected) and plotting

paymentsEqualPayActual = loanCalculator(amount, length, inflation, interest, year, month, day, 'equal payments', 'no')
paymentsEqualPayProjected = loanCalculator(amount, length, projectedInflation, projectedInterest, year, month, day, 'equal payments', 'no')
paymentsEqualPriActual = loanCalculator(amount, length, inflation, interest, year, month, day, 'equal principal payments', 'no')
paymentsEqualPriProjected = loanCalculator(amount, length, projectedInflation, projectedInterest, year, month, day, 'equal principal payments', 'no')

fig9, ax = plt.subplots(1, 2, figsize = (20, 8))

paymentsEqualPayActual['Total Payment'].plot(ax=ax[0], color = 'b')
paymentsEqualPayProjected['Total Payment'].plot(ax=ax[0], color = 'b', alpha = 0.3)
paymentsEqualPriActual['Total Payment'].plot(ax=ax[0], color = 'r')
paymentsEqualPriProjected['Total Payment'].plot(ax=ax[0], color = 'r', alpha = 0.3)
ax[0].set_ylabel('Total Payments (isk)', size = 15)
ax[0].set_xlabel('Year', size = 15)
ax[0].legend(['Equal Payments, Actual','Equal Payments, Projected','Equal Principal Payments, Actual','Equal Principal Payments, Projected'])

paymentsEqualPayActual['End Balance'].plot(ax=ax[1], color = 'b')
paymentsEqualPayProjected['End Balance'].plot(ax=ax[1], color = 'b', alpha = 0.3)
paymentsEqualPriActual['End Balance'].plot(ax=ax[1], color = 'r')
paymentsEqualPriProjected['End Balance'].plot(ax=ax[1], color = 'r', alpha = 0.3)
ax[1].set_ylabel('End Balance (isk)', size = 15)
ax[1].set_xlabel('Year', size = 15)
ax[1].legend(['Equal Payments, Actual','Equal Payments, Projected','Equal Principal Payments, Actual','Equal Principal Payments, Projected'])

fig9.suptitle('Non-Indexed Loans', size = 20)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
Payment Plan 2
Indexed: no

Payments: equal payments

Fixed Interest (%): 6.5

Fixed Inflation (%): 0.0 (irrelevant)
Can you write Python code for it?

payments = loanCalculator(10000000, 25, 0, 6.5, 2017, 5, 8, 'equal payments', 'no')

fig6, ax = plt.subplots(2, 2, figsize = (15, 10))

payments['Total Payment'].plot(ax=ax[0,0])
ax[0,0].set_ylabel('Total Payments (isk)', size = 15)
ax[0,0].set_xlabel('Year', size = 15)

payments['End Balance'].plot(ax=ax[0,1])
ax[0,1].set_ylabel('End Balance (isk)', size = 15)
ax[0,1].set_xlabel('Year', size = 15)

payments['Principal Payment'].plot(ax=ax[1,0])
ax[1,0].set_ylabel('Principal Payment (isk)', size = 15)
ax[1,0].set_xlabel('Year', size = 15)

payments['Interest Payment'].plot(ax=ax[1,1])
ax[1,1].set_ylabel('Interest Payment (isk)', size = 15)
ax[1,1].set_xlabel('Year', size = 15)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
Payment Plan 3
Indexed: yes

Payments: equal principal payments

Fixed Interest (%): 3.5

Fixed Inflation (%): 1.5
Can you write Python code for it?

payments = loanCalculator(10000000, 25, 1.5, 3.5, 2017, 5, 8, 'equal principal payments', 'yes')

fig7, ax = plt.subplots(2, 2, figsize = (15, 10))

payments['Total Payment'].plot(ax=ax[0,0])
ax[0,0].set_ylabel('Total Payments (isk)', size = 15)
ax[0,0].set_xlabel('Year', size = 15)

payments['End Balance'].plot(ax=ax[0,1])
ax[0,1].set_ylabel('End Balance (isk)', size = 15)
ax[0,1].set_xlabel('Year', size = 15)

payments['Principal Payment'].plot(ax=ax[1,0])
ax[1,0].set_ylabel('Principal Payment (isk)', size = 15)
ax[1,0].set_xlabel('Year', size = 15)

payments['Interest Payment'].plot(ax=ax[1,1])
ax[1,1].set_ylabel('Interest Payment (isk)', size = 15)
ax[1,1].set_xlabel('Year', size = 15)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
Payment Plan 4
Indexed: yes

Payments: equal payments

Fixed Interest (%): 3.5

Fixed Inflation (%): 1.5
Can you write Python code for it?

payments = loanCalculator(10000000, 25, 1.5, 3.5, 2017, 5, 8, 'equal payments', 'yes')

fig8, ax = plt.subplots(2, 2, figsize = (15, 10))

payments['Total Payment'].plot(ax=ax[0,0])
ax[0,0].set_ylabel('Total Payments (isk)', size = 15)
ax[0,0].set_xlabel('Year', size = 15)

payments['End Balance'].plot(ax=ax[0,1])
ax[0,1].set_ylabel('End Balance (isk)', size = 15)
ax[0,1].set_xlabel('Year', size = 15)

payments['Principal Payment'].plot(ax=ax[1,0])
ax[1,0].set_ylabel('Principal Payment (isk)', size = 15)
ax[1,0].set_xlabel('Year', size = 15)

payments['Interest Payment'].plot(ax=ax[1,1])
ax[1,1].set_ylabel('Interest Payment (isk)', size = 15)
ax[1,1].set_xlabel('Year', size = 15)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
The figure above shows the relationshiop between the interest rates and the inflation. Initial inspection hints a correlation between the inflation and interest rates, but the rates seem to follow the inflation's dips and rises to quite an extent. Let's inspect this relationship and run the correlations.
Can you write Python code for it?

rate = bankInterests[['Indexed Lowest rate', 'Indexed Highest rate', 'Non-Indexed Lowest rate', 'Non-Indexed Highest rate', 'Inflation']].reset_index()
# Subplot of size 2x2 added
fig3, ax = plt.subplots(2, 2, figsize = (15, 15))
# Rows with NaN removed
rate = rate.dropna()
sns.regplot(x='Inflation',y='Non-Indexed Lowest rate',  ax = ax[0,0],data=rate, fit_reg=True)
sns.regplot(x='Inflation',y='Non-Indexed Highest rate',  ax = ax[0,1],data=rate, fit_reg=True)
sns.regplot(x='Inflation',y='Indexed Lowest rate',  ax = ax[1,0],data=rate, fit_reg=True)
sns.regplot(x='Inflation',y='Indexed Highest rate',  ax = ax[1,1],data=rate, fit_reg=True)
fig3.suptitle('Scatterplots - Inflation vs Rates', size = 20)


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
The scatter plots above show correlations between the inflation and the interest rates. The interest rates increase with the increased inflation. This is an expected behaviour.
To verify the correlations betweeen the Inflation and the interest rates indicated by the scatter plots, we find the Pearson coefficient (correlation coefficient) for each pair. Below is a heatmap that shows the correlation between different forms of loan interest rates and the inflation.
Can you write Python code for it?

fig4= plt.figure(figsize=(15,15))
ax = fig4.add_subplot(111)
# Column titles added to heatmap
ax.set_xticklabels(rate.columns)
ax.set_yticklabels(rate.columns)
cax = ax.matshow(rate.corr(), interpolation='nearest', cmap='Blues')
# Color bar added on the right
fig4.colorbar(cax)
fig4.suptitle('Correlation Heatmap', size = 20)

# Correlation of rates set to a new DataFrame
rateCorrelation = rate.corr()[['Inflation']]
# Correlation of inflation to inflation removed
rateCorrelation = rateCorrelation[rateCorrelation['Inflation'] != 1.0]
# Sorted in a descending order
rateCorrelation = rateCorrelation.sort_values('Inflation',
                                              ascending=False)
# Correlation of rates to inflation displayed
rateCorrelation


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
The table above shows the Pearson coefficient for each pair of inflation and interest rate. According to these results there is a high correlation, the lowest (0.70) being between inflation and the indexed lowest rate and the highest (0.80) between inflation and non-indexed highest rate. This tells us that the banks adjust the interests they're offering, to compensate for the change in inflation. The conclusion here is that the interests on the non-indexed mortgage loans also follow the inflation, making the two loan options not so different in praxis. It's evident that both loan are adjusted to inflation one way or another.
Another very interesting thing to look at is the order of the correlations, highest to lowest. Before we analyse that, lets look at how the interest rates are structured and how the interest payments are calculated.
Indexed:
Yields on indexed accounts consist of interest and indexation. The indexation is calculated on the lowest balance for each month and changes according to the inflation. The indexation is then added to the balance like so:
Start Balance(i+1) = End Balance(i) * Interest Rate(i)

where i is the payment period.

So for indexed loans, the interest payments are calculated by using the interest rate on the CPI adjusted balance like so
Interest Payment(i) = Start Balance(i) * Interest Rate(i)

Non-Indexed rates:
In the case of non-indexed loans we don't have indexation, but the inflation still plays a roll. To see how, lets break down the interest rate.
Interest Rate(i) = Bank Interest rate(i) + Projected Inflation Rate(i) + Risk Premium Rate{i)

 where i is the payment period.

There is always uncertainty in projecting or forecasting inflation, especially in Iceland.  The Risk Premium rate is the added rate lenders use to mitigate the risk of using the projected inflation.
Loan Payment Plan Calculator
loanCalculator(amount, length, inflation, interest, issueYear, issueMonth, issueDay, loantype, indexation)
The function loanCalculator is a dynamic function that returns a loan...
Can you write Python code for it?

def loanCalculator(amount, length, inflation, interest, issueYear, issueMonth, issueDay, loantype, indexation):

    periods = length * 12
    issueDate = dt.date(issueYear, issueMonth, issueDay)

    columns = ['Start Balance', 'Total Payment', 'Principal Payment', 'Interest Payment', 'End Balance']
    index = pd.date_range(start = issueDate, periods = periods, freq = 'M')
    payments = pd.DataFrame(index = index, columns = columns)

    # Dealing with interest and inflation rates, whether the input is a series or an int/float

    if type(interest) == pd.Series:
        monthlyInterestRate = (interest/12)/100
    else:
        monthlyInterestRate=[]
        for i in range(len(payments)):
            monthlyInterestRate.append((interest/12)/100)

        monthlyInterestRate=pd.Series(monthlyInterestRate)

    if type(inflation) == pd.Series:
        monthlyInflationRate = (inflation/12)/100
    else:
        monthlyInflationRate=[]
        for i in range(len(payments)):
            monthlyInflationRate.append((inflation/12)/100)

        monthlyInflationRate=pd.Series(monthlyInflationRate)

    # This for loop calculates the payment plan for the 4 loan options.

    for i in range(len(payments)-1):

        if loantype == 'equal principal payments' and indexation == 'no': # Non-Indexed Equal Principal Payments

            # first line of payment plan

            payments.iloc[0,0] = amount
            payments.iloc[0,2] = amount/periods
            payments.iloc[0,3] = payments.iloc[0,0] * monthlyInterestRate[0]
            payments.iloc[0,1] = payments.iloc[0,2] + payments.iloc[0,3]
            payments.iloc[0,4] = payments.iloc[0,0] - payments.iloc[0,2]

            i=i+1

            payments.iloc[i,0] = payments.iloc[(i-1),4]
            payments.iloc[i,2] = amount/periods
            payments.iloc[i,3] = payments.iloc[i,0] * monthlyInterestRate[i]
            payments.iloc[i,1] =...


I am working on the file "MBA_S17/Hannesson-Nielsen-Mortgage_Payments.ipynb".
The first task is:
When comparing the actual payments to the projected payment plan, we can see there is a big difference.
For the indexed loans the actual payments deviate from the projection very early on in the payment process and end up being much higher then anticipated. In turn the balance/principal behaves similarly. It starts off decreasing very slowly until it hits a significant hike before starting to drop again and level off with the projections.
Looking at the non-indexed loans we also see a massive difference. What should be a very steady payment process turns out to be a very fluctuating one, with payments rising fast and doubling in and after the mid 2000's before they finally even out. We also see the balance/principal decreasing at a slower rate in the beginning.
This variability needs to be addressed to try to make sense of it all.
Variance
The actual payments we have seen vary greatly in terms of total payment, something a lendee wants to try to avoid. Not knowing how the payments will develop is very unfortunate, especially since salaries are not CPI indexed and could easily fall behind, leaving the lendee in massive unforseen debt. The following will shed a light on the variability involved.
Can you write Python code for it?

# Creating a dataframe including the total payments for the 4 types of loans and drawing box plots

equalMonthlyTotalPayments = {'Indexed Equal Payment': indPaymentsEqualPayActual['Total Payment'],
            'Non-Indexed Equal Payment': paymentsEqualPayActual['Total Payment'],
                     'Indexed Equal Principal': indPaymentsEqualPriActual['Total Payment'],
                      'Non-Indexed Equal Principal': paymentsEqualPriActual['Total Payment']}

fig10, ax = plt.subplots(figsize = (17,10))

equalMonthlyTotalPayments = pd.DataFrame(data = equalMonthlyTotalPayments)

sns.boxplot(data=equalMonthlyTotalPayments, ax=ax, palette = 'muted', width = 0.5)
ax.tick_params(labelsize = 16)
ax.set_ylabel('Total Monthly Payment (isk)', size = 20)
fig10.suptitle('Box Plots - Total Monthly Payment', size = 20)


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
A company is considered paying significantly more than the prevailing wage if the difference between its proposed wage and the prevailing wage exceeds $5,0000.
Companies with most instances of paying significantly more are: Google, Cedent Consulting, Microsoft, YourPeople (Zenefits) and Uber. Three of them are technology firms while two are consulting firms.
Software engineers are more likely to earn wages that well exceed the prevailing wage. Business analysts and consultants are less likely to be paid 50k more than the prevailing wage.
Adjust for Cost of Living - Case of Business Analyst & Software Engineer
Can you write Python code for it?

subset2 = subset1[['JOB_TITLE', 'WAGE_RATE_OF_PAY_FROM', 'WORKSITE_STATE']]
av_wage_state = subset2.groupby(['JOB_TITLE', 'WORKSITE_STATE'])['WAGE_RATE_OF_PAY_FROM'].mean()
av_wage_state.to_frame()


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Based on the average wage by state without adjusting for cost of living, we may be attempted to conclude that working as a business analyst in California and Washington are not bad at all. However, California and Washington are no longer in the graph after we adjust for cost of living.
Working as a business analyst in West Virginia, Vermont and Oregon may be the best choices as these three states appear in both graphs.
Case2: Software Engineer
Can you write Python code for it?

se = av_wage_state['SOFTWARE ENGINEER'].to_frame()
se = se.reset_index()
se

blend2 = pd.merge(se, sarpps, how = 'right', on = 'WORKSITE_STATE')
blend2['Adjusted Wage'] = blend2['WAGE_RATE_OF_PAY_FROM'] / blend2['RPP'] * 100
blend2

top5_ = blend2[['State', 'WAGE_RATE_OF_PAY_FROM']].sort_values('WAGE_RATE_OF_PAY_FROM', ascending = False).head()
top5_ = top5_.set_index('State')

fig, ax = plt.subplots(figsize = (8, 5))
fig.suptitle('Software Engineer - Average Wage by State', fontsize=14, fontweight='bold')
top5_.plot(kind = 'bar',
          ax = ax,
          color = 'orange',
          alpha = 0.5,
          legend = False
          )

top5adjust_ = blend2[['State', 'Adjusted Wage']].sort_values('Adjusted Wage', ascending = False).head()
top5adjust_ = top5adjust_.set_index('State')

fig, ax = plt.subplots(figsize = (8, 5))
fig.suptitle('Software Engineer - Adjusted Average Wage by State', fontsize=14, fontweight='bold')
top5adjust_.plot(kind = 'bar',
                ax = ax,
                color = 'orange',
                alpha = 0.5,
                legend = False
                )


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Case1: Business Analyst
Can you write Python code for it?

ba = av_wage_state['BUSINESS ANALYST'].to_frame()
ba = ba.reset_index()
ba


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Data Input
1. Annual Disclosure Data
The annual disclosure data on LCA programs for the fiscal year of 2016 are stored in an Excel file and will be accessed directly from the web. (Note: it takes a few minutes to import the entire dataset)
Can you write Python code for it?

ssl._create_default_https_context = ssl._create_unverified_context

url = 'https://www.foreignlaborcert.doleta.gov/docs/Performance_Data/Disclosure/FY15-FY16/H-1B_Disclosure_Data_FY16.xlsx'
cols = list(range(5)) + [7, 10, 19, 25, 30, 32, 37]
h1b = pd.read_excel(url, usecols = cols)
h1b.head()


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Merging Average Wage by State & Regional Price Parities
Values in the 'WORKSITE_STATE' column above are abbreviations while values in the 'State' column of the regional price parities dataframe are full names. We find a state abbreviations table online to solve for the discrepancy.
Can you write Python code for it?

url2 = 'http://www.softschools.com/social_studies/state_abbreviations/'
cl = requests.get(url2)
cl.status_code

cl_soup = BeautifulSoup(cl.content, 'html.parser')


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Of the 65,000 visas allocated to the capped H-1B program, a total of 6800 are reserved for the H-1B1: 1,400 for Chile and 5,400 for Singapore. There is a separate annual quota of 10,500 E-3 visas.
Our analysis will focus on H-1B visas since E-3 and H-1B1 visas only account for 2% of the certified cases.
Can you write Python code for it?

h1b_c2 = h1b_c[h1b_c['VISA_CLASS'] == 'H-1B']
h1b_c2['WAGE_UNIT_OF_PAY'].value_counts()


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Since District of Columbia is not in the table, we append a row to the dataframe.
Can you write Python code for it?

sa = pd.read_html(str(cl_soup.find_all('table')[0]), header=0)[2]
sa.loc[len(sa.index)] = ['DISTRICT OF COLUMBIA', 'DC']
sa = sa.sort_values('State')
sa = sa.reset_index(drop = True)
sa


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
This dataset has more than half a million rows. It is more feasible to work with its subsets. Status associated with a particular case has four possible values: Withdrawn, Certified-Withdrawn, Certified and Denied. We are only going to look at cases that have a status of 'Certified'.
Can you write Python code for it?

h1bcopy = h1b.copy() #make a copy of the original dataframe
h1bcopy = h1bcopy.set_index('CASE_NUMBER')

h1b_c = h1bcopy[h1bcopy['CASE_STATUS'] == 'CERTIFIED']
h1b_c.shape


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Visa class associated with a particular case also has possible values as there are three variants of the H-1B visa. The E-3 visa is for Australian nationals while the H-1B1 visa is for citizens of Singapore and Chile.
Can you write Python code for it?


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
What states have most employers that provide visa sponsorship?
Can you write Python code for it?

states = h1b_c3.groupby('EMPLOYER_STATE')['EMPLOYER_NAME'].nunique().sort_values(ascending = False)
states.head()


I am working on the file "MBA_S17/Huh-Ma-H1B Program.ipynb".
The first task is:
Working with Subsets of the Annual Disclosure Data
Can you write Python code for it?


I am working on the file "MBA_S17/John-Chihyun-US SUV Demand.ipynb".
The first task is:
CPI for New and Used Vehicles Trend
Can you write Python code for it?

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

inds4 = inds['CPI: New']
inds4.plot(ax = ax, stacked = True)

ax.set_xlabel('Year')
ax.set_ylabel('Consumer Price Index (Index 1982-1984 = 100)')
ax.set_title('CPI for New Vehicles Trend, 1986-2017')


I am working on the file "MBA_S17/John-Chihyun-US SUV Demand.ipynb".
The first task is:
Factors Correlated to SUVs Demand
Can you write Python code for it?

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

ax.scatter(inds['CPI: New'], inds['Light Weight Truck Sales Percentage'])
ax.set_title('Correlation between CPI and Light Truck Sales Percentage')
ax.set_ylabel('Light Truck Sales Percentage')
ax.set_xlabel('CPI: New Vehicles')

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

inds['Ratio of CPI to DPI'] = inds['CPI: New'] / inds['Real DPI']

ax.scatter(inds['Ratio of CPI to DPI'], inds['Light Weight Truck Sales Percentage'])
ax.set_title('Correlation between CPI and Light Truck Sales Percentage')
ax.set_ylabel('Light Truck Sales Percentage')
ax.set_xlabel('Ratio of CPI to DPI')

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

ax.scatter(inds['Real DPI'], inds['Light Weight Truck Sales Percentage'])
ax.set_title('Correlation between Real DPI and Light Truck Sales Percentage')
ax.set_ylabel('Light Truck Sales Percentage')
ax.set_xlabel('Real DPI')

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

ax.scatter(inds['Oil Price'], inds['Light Weight Truck Sales Percentage'])
ax.set_title('Correlation between Oil Price and Light Truck Sales Percentage')
ax.set_ylabel('Light Truck Sales Percentage')
ax.set_xlabel('Oil Price')

indicators_updated = ['DCOILWTICO', 'TOTALSA', 'DLTRUCKSSAAR']
start_date = dt.datetime(2000, 1, 1)
inds_updated = web.DataReader(indicators_updated, "fred", start_date)
inds_updated['Light Weight Truck Sales Percentage'] = inds_updated['DLTRUCKSSAAR'] / inds_updated['TOTALSA']
end = inds_updated.index[-1]

inds_updated.columns = ['Oil Price', 'Total Vehicle Sales', 'Light Weight Truck Sales', 'Light Weight Truck Sales Percentage']

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

ax.scatter(inds_updated['Oil Price'], inds_updated['Light Weight Truck Sales Percentage'])
ax.set_title('Correlation between Oil Price and Light Truck Sales Percentage')
ax.set_ylabel('Light Truck Sales Percentage')
ax.set_xlabel('Oil Price')


I am working on the file "MBA_S17/John-Chihyun-US SUV Demand.ipynb".
The first task is:
Real Disposable Personal Income Trend
Can you write Python code for it?

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

inds3 = inds['Real DPI']
inds3.plot(ax = ax, stacked = True)

ax.set_xlabel('Year')
ax.set_ylabel('Real DPI')
ax.set_title('Real Disposable Personal Income Trend, 1986-2017')


I am working on the file "MBA_S17/John-Chihyun-US SUV Demand.ipynb".
The first task is:
Working Age Population Trend
Can you write Python code for it?

seab.set_style('dark')
fig, ax = plt.subplots(figsize=(10,7))

inds3 = inds['Working Age Population']
inds3.plot(ax = ax, stacked = True)

ax.set_xlabel('Year')
ax.set_ylabel('Working Age Population')
ax.set_title('Working Age Population Trend, 1986-2017')


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
Another interesting comparison is between months. We would like to examine and compare the total number of miles traveled by CitiBike users in January, February, and March. A higher number of miles traveled in a given month would indicate more rentals and/or more miles traveled per use. Either way, there is a trend toward heavier bike usage.
Our hypothesis is that riders will ride their bikes more in the beginning of the year, because New Year’s resolutions will push people to ride a bike to work instead of taking the train or a cab. We also need to factor in the poor weather during this time of year, which may deter bike riders, but we think that there will be a spike in January and then a downward trend month to month.
Can you write Python code for it?

January_Miles = CitiBike [CitiBike['Month'] == 1]
January_Miles_Total = January_Miles [['Total Miles']].sum ()

February_Miles = CitiBike [CitiBike['Month'] == 2]
February_Miles_Total = February_Miles [['Total Miles']].sum ()

March_Miles = CitiBike [CitiBike['Month'] == 3]
March_Miles_Total = March_Miles [['Total Miles']].sum ()

print (January_Miles_Total)
print (February_Miles_Total)
print (March_Miles_Total)

Total_Mileage = pd.DataFrame ({'January' : January_Miles_Total,
                               'February' : February_Miles_Total,
                               'March' : March_Miles_Total})

Total_Mileage = Total_Mileage[['January', 'February', 'March']]

print (Total_Mileage)

fig, ax = plt.subplots(1)
Total_Mileage.plot(ax=ax, kind = 'bar', title = 'Total Miles Covered per Month Q1')

ax.legend(['JAN', 'FEB', 'MAR'], loc='best')
ax.set_xlabel('Month')
ax.set_ylabel('Total Miles')
ax.set_ylim (0,2100000)


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
First, we must import the data from CitiBike's website. The data accessed throught the 'Get the data' link at the bottom left corner of the following page http://datawrapper.dwcdn.net/33zqP/6/. This data is updated in near-real-time. When we run our anlysis, data available was from January 1, 2017, through March 31, 2017. Due to the character length of the link address for the data file, it is not redable directly by a .read_csv() function in Python and so we use the urllib.request functionality as shown below to access the source website directly through python.
Can you write Python code for it?


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
From this comparison, we can see that riders typically travel 50% farther on weekend trips than weekdays.
We will build on this insight in later graphs.
Can you write Python code for it?

Average_Mileage = pd.DataFrame ({'Weekdays' : Weekday_Average, 'Weekends' : Weekend_Average})

Average_Mileage = Average_Mileage [['Weekdays', 'Weekends']]

print (Average_Mileage)


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
In order to manipulate and sort the data based on day of the week and month, we must convert the date information from a .csv format to python datetime format.
Can you write Python code for it?

CitiBike['Date'] =  pd.to_datetime(CitiBike['Date'])
CitiBike.head ()

CitiBike.dtypes


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
Next, we will retitle each column so that it's easier to understand what we're looking at.
Can you write Python code for it?

titles = ['Total Trips', 'Total Miles', 'Day of Week', 'Month']
CitiBike.columns = titles
CitiBike.head()


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
Now that Python recognizes the data in the Date column as calendar dates, we can add a column to classify each data point by day of the week and by month. This will ultimately allow us to compare usage on Monday vs. Tuesday, e.g., or January vs. February.
Can you write Python code for it?

CitiBike['Day of Week'] = CitiBike['Date'].dt.weekday_name
CitiBike.head()

CitiBike['Month'] = CitiBike['Date'].dt.month
CitiBike.head()


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
Now that we have individual dataframes for each day of the week, we can create larger dataframes for week days and weekends.
Can you write Python code for it?

Weekend_List = ['Saturday', 'Sunday']
Weekday_List = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
CitiBike [CitiBike ['Day of Week'].isin (Weekend_List)].head ()

CitiBike [CitiBike ['Day of Week'].isin (Weekday_List)].head ()


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
The analysis shows a steady downward trend throughout the week – riders are much more likely to rent a CitiBike on Monday than on Thursday. This is fairly logical. It’s easy to imagine that riders are energized on Monday after a relaxing weekend, and tired, busy, and distracted later in the week. This means that they have more energy and are more willing to ride a bike to work at the beginning of the week. Only those who are going short distances want to ride a bike.
However, there is a considerable spike on Fridays, up to more than 2.5 miles travelled by the average CitiBike rider. This could represent a number of things, but it is certainly related to the impending weekend. Riders are energized by the end of the week, and may bike more at the end of the day because they have the free time. Alternatively, riders may be working from home and going for longer rides during a break in the middle of the day.
Can you write Python code for it?

fig, ax = plt.subplots(1)
Weekday_Daily_Mileage.plot(ax=ax, kind = 'bar', title = 'Daily Weekday Average Miles per Rider Q1')

ax.legend(['MON', 'TUE', 'WED', 'THU', 'FRI'], loc='best')
ax.set_xlabel('Days of the week (Weekday)')
ax.set_ylabel('Average number of miles')
ax.set_ylim (0,3.0)


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
To finalize the daily average comparisons, we need to create individual dataframes for each day of the week.
Can you write Python code for it?

CitiBike [CitiBike['Day of Week'] == 'Sunday']
CitiBike [CitiBike['Day of Week'] == 'Monday']
CitiBike [CitiBike['Day of Week'] == 'Tuesday']
CitiBike [CitiBike['Day of Week'] == 'Wednesday']
CitiBike [CitiBike['Day of Week'] == 'Thursday']
CitiBike [CitiBike['Day of Week'] == 'Friday']
CitiBike [CitiBike['Day of Week'] == 'Saturday']
CitiBike [CitiBike['Month'] == 1]
CitiBike [CitiBike['Month'] == 2].head ()


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
We now have all the useful data columns, but the index column needs to be replaced. We want to analyze this data by date, so we need to make the date column the index.
Can you write Python code for it?

CitiBike = CitiBike.set_index ('Date')
CitiBike.head()


I am working on the file "MBA_S17/Love-Serunjogi-CitiBikeRiderData.ipynb".
The first task is:
We see that this data is has much more information than we need. For example, it includes total annual membership, which we do not need for this analysis. Thus, we have removed this column to prioritize the data that will most impact daily and monthly usership.
Can you write Python code for it?

CitiBike.drop(CitiBike.columns[[3,4,5]], axis = 1, inplace = True)
CitiBike.head()


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
2.1.2 Cleaning Housing Data
Select Relevant Variables
Can you write Python code for it?

# list of all variables
Rent.columns.values

# Select Only relevant data

Rent = Rent[['name', 'neighbourhood_cleansed', 'city', 'zipcode', 'latitude', 'longitude',
          'property_type', 'room_type', 'accommodates','bathrooms', 'bedrooms', 'beds', 'square_feet', 'price',
           'weekly_price', 'monthly_price', 'review_scores_value']]

Rent.head(2)

nrow = len(Rent.index)
nrow


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
2.2.2 Cleaning Crime Data
Select Relevant Values
Can you write Python code for it?

# list of all variables

Crime.columns.values

# Select only relevant data

Crime = Crime [['Crime', 'YTD_Current', 'YTD_Prior', 'Precinct']]

# Remove non-numeric characters from Precinct column

Crime['Precinct'].replace(regex=True,inplace=True,to_replace=r'\D',value=r'')
Crime.head()


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Add Borough and Neighborhood Data
Can you write Python code for it?

# reset indices
Precinct = Precinct.reset_index()

nrow = len(Precinct.Zip)
nrow


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
After cleaning the data we finished with four dataframes: Rent, Rent_Private, Crime and Crime_Total. We will use these three to produce visual aids to better understand how they relate.
3. Visualizing the Data
3.1 Housing Data
In here we will just look into the housing data, and see how different are the prices in the different boroughs and different neighborhoods of Manhattan
Can you write Python code for it?

# Import seaborn package

import seaborn as sns


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Clean Price
Can you write Python code for it?

day_price = []
for i in range(nrow):
# remove commas ans $ sign, convert into float
    day_price.append((float(Rent.price[i].replace(',','')[1:])))

# Drop old price column
Rent = Rent.drop(['price'], axis = 1)

# Add new column with calculated data
Rent['day_price'] = day_price

Rent.head(2)


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Create New Dataframe with just the Private Rooms available to rent
Can you write Python code for it?

# Filter table based on room_type Column
Rent_Private = Rent.loc[Rent['room_type'] == 'Private room']

# Reset index in the new table
Rent_Private.reset_index(inplace=True, drop = True)

# Remove outliers to keep data clean. I set ouliers as any private room above $300
Rent_Private = Rent_Private.loc[Rent_Private['day_price'] < 300]

Rent_Private.head(2)
#Rent_Private.dtypes


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Create New Dataframe with just the total crimes row for each Precinct
Can you write Python code for it?

# Filter table based on Crime Column
Crime_Total = Crime.loc[Crime['Crime'] == 'TOTAL']

# Reset index in the new table
Crime_Total.reset_index(inplace=True, drop = True)

Crime_Total.head()
#Crime_Total.dtypes


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Create New columns to store the correct Borough and Neighborhood data
Can you write Python code for it?

# Create new list and insert Borough and Neighborhood data based on index

borough_table = list()
neighborhood_table = list()
for i in range(nrow):
    if Rent.zipcode[i] in zip_code_unique:
        borough_table.append(borough[zip_code_unique.index(Rent.zipcode[i])])
        neighborhood_table.append(neighborhood[zip_code_unique.index(Rent.zipcode[i])])
    else:
        borough_table.append("N/A")
        neighborhood_table.append("N/A")

Rent['borough'] = borough_table
Rent['Neighborhood'] = neighborhood_table

# Drop rows that have borough or Neighborhood N/A

# Remove row if borough is N/A
Rent = Rent.loc[Rent['borough'] != 'N/A']

# reset indices
Rent = Rent.reset_index()

# reset nrow
nrow = len(Rent.index)
nrow


# Create new list and insert Borough and Neighborhood data based on index

borough_table = list()
neighborhood_table = list()
for i in range(nrow):
    if Precinct.Zip[i] in zip_code_unique:
        borough_table.append(borough[zip_code_unique.index(Precinct.Zip[i])])
        neighborhood_table.append(neighborhood[zip_code_unique.index(Precinct.Zip[i])])
    else:
        borough_table.append("N/A")
        neighborhood_table.append("N/A")

Precinct['borough'] = borough_table
Precinct['Neighborhood'] = neighborhood_table

# Drop rows that have borough or Neighborhood N/A

# Remove row if borough is N/A
Precinct = Precinct.loc[Rent['borough'] != 'N/A']

Precinct.head()


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Make sure columns have correct data type
Can you write Python code for it?

# update new number rows
nrow = len(Crime.index)

# Precinct dtype should be str
Crime.Precinct = Crime.Precinct.astype(np.str)

# Remove commas and periods fron number of crimes
Crime.YTD_Current.append(Crime.YTD_Current.replace(",",""))
Crime.YTD_Prior.append(Crime.YTD_Prior.replace(",",""))

Crime.head()


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Merge Crime and Precinct Data
Can you write Python code for it?

# Merge the two Dataframes to include Zipcode

Combo = pd.merge(Crime, Precinct,          # left and right df's
                 how='inner',              # Inner Merge
                 left_on='Precinct',       # link with this variable/column
                 right_on='Precinct',      # link with this variable/column
                indicator = True)

Combo.dtypes

Combo.head()

# Update Crime df with data from Combo and remove indicator

Crime = Combo [['Crime', 'YTD_Current', 'YTD_Prior', 'Precinct', 'Zip', 'borough','Neighborhood']]

Crime.head()


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Plot Average Price by Total Crimes, with Total Apartments as the size of the markers
Can you write Python code for it?

sns.set(style="whitegrid",
        color_codes=True)

# Plot graph
g = sns.lmplot('YTD_Current', 'day_price',
           data=Combined,
           fit_reg=False,
           scatter=True,
           palette="Red",
           size = 6,
           aspect = 1.5,
           scatter_kws={"marker": "D", "s": Combined.Total,"color": "steelblue"})

# Annotate some Neighborhoods based on their data coordinates
plt.annotate('Lower East Side', xy=(3123,107), xytext = (-20, 10), xycoords = 'data',
                    textcoords = 'offset points', ha = 'right', va = 'bottom', fontsize=8,
                    bbox = dict(boxstyle = 'round,pad=0.5', fc = 'grey', alpha = 0.5),
                    arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

plt.annotate('Chelsea', xy=(2335,127), xytext = (40, 20), xycoords = 'data',
                    textcoords = 'offset points', ha = 'right', va = 'bottom', fontsize=8,
                    bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
                    arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

plt.annotate('Gramercy Park', xy=(1811,124), xytext = (-15, 12), xycoords = 'data',
                    textcoords = 'offset points', ha = 'right', va = 'bottom', fontsize=8,
                    bbox = dict(boxstyle = 'round,pad=0.5', fc = 'grey', alpha = 0.5),
                    arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

plt.annotate('Greenpoint', xy=(960,88.5), xytext = (-30, 10), xycoords = 'data',
                    textcoords = 'offset points', ha = 'right', va = 'bottom', fontsize=8,
                    bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellowgreen', alpha = 0.5),
                    arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

plt.annotate('Northwest Brooklyn', xy=(4700,98), xytext = (-20, 10), xycoords = 'data',
                    textcoords = 'offset points', ha = 'right', va = 'bottom', fontsize=8,
                    bbox = dict(boxstyle =...


I am working on the file "MBA_S17/Oliveira_CrimeRentNYC.ipynb".
The first task is:
Remove any row with a missing Zipcode or Precinct
Can you write Python code for it?

# update new number rows
nrow = len(Crime.index)

# list of indices where zipcode is missing
non_missing_zip = [ind for ind in range(nrow) if pd.isnull(Crime.Zip)[ind] == False]

# list of indices where Precinct is missing
non_missing_Pre = [ind for ind in range(nrow) if pd.isnull(Crime.Precinct)[ind] == False]

# Keep only rows where non_missing is True
Crime = Crime.ix[non_missing_zip,]

Crime = Crime.ix[non_missing_Pre,]