-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bonus.py
66 lines (46 loc) · 1.53 KB
/
Bonus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Import dependencies
# Pandas
import pandas as pd
import psycopg2
# Matplotlib
import matplotlib.pyplot as plt
# NumPy
import numpy as np
import scipy.stats as st
from config import password
from sqlalchemy import create_engine
engine = create_engine(f'postgresql://postgres:{password}@localhost:5432/EmployeeSQL')
connection = engine.connect()
data_employees = pd.read_sql("select * from data_employees", connection)
data_employees.head()
# Salaries analysis
data_salaries = pd.read_sql("SELECT * from data_salaries", connection)
data_salaries.head()
data_salaries.min()
employees_salary = pd.merge(data_employees, data_salaries, on = "emp_no")
employees_salary
employees_salary2= employees_salary.rename(columns={"emp_title":"title_id"})
employees_salary2
# Create a histogram to visualize the most common salary ranges for employees.
x = employees_salary2['salary']
plt.hist(x, bins=15)
plt.show()
#Create a bar chart of average salary by title
titles_salary= pd.read_sql('select * from data_titles', connection)
titles_salary
# Merging tables
emp_salary_title = pd.merge(employees_salary2, titles_salary, on = "title_id")
emp_salary_title
title_avg = emp_salary_title.groupby(['title']).mean()['salary']
title_avg.round(2)
x_axis = title_avg.index.values
x_axis
y_axis = title_avg.index.values
y_axis
#bar chart using pyplot
plt.bar(x_axis, y_axis)
plt.xticks(rotation = 45)
plt.title("Average Salary per Job Title")
plt.xlabel("Job Title")
plt.ylabel("Salary ($)")
plt.show()