
Добавил:
KaFaka
t.me
Инфо для ГУАП студентов от меня: https://kafaka.notion.site/99e6d9b70ca74f7baef3daea17839e5a
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:4 курс 1 семестр / Лабораторные / Python / LR8_4
.py import psycopg2
import pandas as pd
import matplotlib.pyplot as plt
# Connect to the database
conn = psycopg2.connect(database="students", user="postgres", password="123", host="127.0.0.1", port="5432")
cursor = conn.cursor()
# Run the SQL query
query = "SELECT e.department_id, MIN(e.salary) as min_salary, m.last_name as manager_last_name " \
"FROM employees e " \
"JOIN employees m ON e.manager_id = m.employee_id " \
"GROUP BY e.department_id, m.last_name "
cursor.execute(query)
# Fetch the result and store it in a Pandas dataframe
result = cursor.fetchall()
df = pd.DataFrame(result, columns=["department_id", "min_salary", "manager_last_name"])
# Plot the data
plt.barh(df["manager_last_name"], df["min_salary"], color='red')
plt.xlabel("Фамилия менеджера")
plt.ylabel("Минимальная заработная плата")
plt.title("Минимальная зарплата по менеджерам")
plt.show()
# Close the cursor and connection
cursor.close()
conn.close()
import pandas as pd
import matplotlib.pyplot as plt
# Connect to the database
conn = psycopg2.connect(database="students", user="postgres", password="123", host="127.0.0.1", port="5432")
cursor = conn.cursor()
# Run the SQL query
query = "SELECT e.department_id, MIN(e.salary) as min_salary, m.last_name as manager_last_name " \
"FROM employees e " \
"JOIN employees m ON e.manager_id = m.employee_id " \
"GROUP BY e.department_id, m.last_name "
cursor.execute(query)
# Fetch the result and store it in a Pandas dataframe
result = cursor.fetchall()
df = pd.DataFrame(result, columns=["department_id", "min_salary", "manager_last_name"])
# Plot the data
plt.barh(df["manager_last_name"], df["min_salary"], color='red')
plt.xlabel("Фамилия менеджера")
plt.ylabel("Минимальная заработная плата")
plt.title("Минимальная зарплата по менеджерам")
plt.show()
# Close the cursor and connection
cursor.close()
conn.close()