Week 3 was Presidents' Day, no class
import math
from matplotlib import pyplot
import random
def Interest_normal(principal):
rate=random.normalvariate(0.03,0.015)
return principal*rate
#mean is 0.03, standard deviation is 0.015. Imagine a variable return on stocks, or inflation, for instance.
#simulation of 10 years of variable interest
years=10
sims=10000
end_balances=[]
for i in range(sims):
time=0
balance=1200
while(time<years):
balance+=Interest_normal(balance)
time+=1
end_balances.append(balance)
pyplot.hist(end_balances, bins=20)
pyplot.show()
pyplot.boxplot(end_balances)
pyplot.show()
import pandas as pd
import numpy as np
import seaborn as sns
employees = pd.read_excel('employee_data.xlsx')
employees.head()
Employee | Gender | Age | Prior Experience | Beta Experience | Education | Annual Salary | |
---|---|---|---|---|---|---|---|
0 | 1 | 1 | 39 | 5 | 12 | 4 | 57700 |
1 | 2 | 0 | 44 | 12 | 8 | 6 | 76400 |
2 | 3 | 0 | 24 | 0 | 2 | 4 | 44000 |
3 | 4 | 1 | 25 | 2 | 1 | 4 | 41600 |
4 | 5 | 0 | 56 | 5 | 25 | 8 | 163900 |
#last time we used groupby. This week we'll use crosstabs to create a summary table
table = pd.crosstab(employees.Education, employees.Gender)
table
Gender | 0 | 1 |
---|---|---|
Education | ||
0 | 2 | 8 |
2 | 9 | 10 |
4 | 46 | 69 |
6 | 24 | 27 |
8 | 4 | 5 |
table2 = pd.crosstab(employees.Gender, employees.Education)
table2
Education | 0 | 2 | 4 | 6 | 8 |
---|---|---|---|---|---|
Gender | |||||
0 | 2 | 9 | 46 | 24 | 4 |
1 | 8 | 10 | 69 | 27 | 5 |
sns.heatmap(table2)
<AxesSubplot:xlabel='Education', ylabel='Gender'>
sns.heatmap(table2,annot=True,linewidths=.5,cmap="YlGnBu")
<AxesSubplot:xlabel='Education', ylabel='Gender'>
dict = {
"FirstName": "Jonathan",
"LastName": "Freeman",
"LoginCount": 4,
"isWriter": True,
"WorksWith": ['Spantree Technology Group', 'InfoWorld'],
"Pets": [
{
"name": "Lilly",
"type": "Raccoon"
}
]
}
dict
{'FirstName': 'Jonathan', 'LastName': 'Freeman', 'LoginCount': 4, 'isWriter': True, 'WorksWith': ['Spantree Technology Group', 'InfoWorld'], 'Pets': [{'name': 'Lilly', 'type': 'Raccoon'}]}
my_dict = {'Computer':1500,'Monitor':300,'Printer':150,'Desk':250}
my_dict
{'Computer': 1500, 'Monitor': 300, 'Printer': 150, 'Desk': 250}
df = pd.DataFrame(list(my_dict.items()),columns = ['Products','Prices'])
df
Products | Prices | |
---|---|---|
0 | Computer | 1500 |
1 | Monitor | 300 |
2 | Printer | 150 |
3 | Desk | 250 |