import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
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 |
sns.relplot(x='Age', y='Annual Salary', data=employees, kind='scatter')
plt.show()
sns.relplot(x='Age', y='Annual Salary', data=employees, kind='line')
plt.show()
sns.lmplot(x='Age', y='Annual Salary', data=employees)
plt.show()
sns.regplot(x='Age', y='Annual Salary', data=employees)
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees)
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="bar")
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="box")
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="strip")
plt.show()
sns.catplot(y='Education', x='Annual Salary', data=employees, kind="strip",orient="h")
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="swarm")
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="violin")
plt.show()
sns.catplot(x='Education', y='Annual Salary', data=employees, kind="point")
plt.show()
sns.displot(x='Annual Salary', data=employees, kind="hist")
plt.show()
sns.displot(x='Annual Salary', data=employees, kind="kde")
plt.show()
sns.displot(x='Annual Salary', data=employees, kind="ecdf")
plt.show()
sns.rugplot(x='Annual Salary', data=employees)
plt.show()
sns.displot(x='Annual Salary', data=employees, kind="kde")
sns.rugplot(x='Annual Salary', data=employees)
plt.show()
sns.jointplot(x="Age", y='Annual Salary', data=employees, hue="Education")
plt.show()
sns.jointplot(x="Age", y='Annual Salary', data=employees, hue="Education", kind='hist')
plt.show()
sns.jointplot(x="Age", y='Annual Salary', data=employees, kind='hist')
plt.show()
sns.jointplot(x="Age", y='Annual Salary', data=employees)
plt.show()
This is the part we didn't get to. we'll talk about it more next week, but in case you need the code for something in the homework...
If you haven't already installed this package, you will need to do so before continuing.
import json
This is our dictionary example from the end of the last class
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'}]}
This is another example of a dictionary. We are going to turn it from text (which is all json is), into a dictionary using the json package.
person='{"name":"Bob", "languages": ["English", "French"]}'
person_dict=json.loads(person)
person_dict
{'name': 'Bob', 'languages': ['English', 'French']}
look inside the dictionary at one of the variables
person_dict['languages']
['English', 'French']
If you have a json file, you can load it this way
with open('path_to_file/filename.json') as f:
data=json.load(f)
another way to import json into a dictionary
dict_json=json.dumps(dict)
dict_json
'{"FirstName": "Jonathan", "LastName": "Freeman", "LoginCount": 4, "isWriter": true, "WorksWith": ["Spantree Technology Group", "InfoWorld"], "Pets": [{"name": "Lilly", "type": "Raccoon"}]}'
This is the dictionary from before. notice it's now a string, which is all json is, so you can export it to a file if you wanted.