Добавил:
KaFaka
t.me
Установите расширение 'SyncShare' для решения тестов в LMS (Moodle): https://syncshare.naloaty.me/ . На всякий лучше отключить блокировщик рекламы с ним. ||
Как пользоваться ChatGPT в России: https://habr.com/ru/articles/704600/ ||
Также можно с VPNом заходить в bing.com через Edge браузер и общаться с Microsoft Bing Chat, но в последнее время они форсят Copilot и он мне меньше нравится. ||
Студент-заочник ГУАП, группа Z9411. Ещё учусь на 5-ом курсе 'Прикладной информатики' (09.03.03). ||
Если мой материал вам помог - можете написать мне 'Спасибо', мне будет очень приятно :)
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:4 курс 1 семестр / Лабораторные / Python / LR8_6
.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 l.city, AVG(e.salary) as avg_salary " \
"FROM employees e " \
"JOIN locations l ON e.location_id = l.location_id " \
"GROUP BY l.city"
cursor.execute(query)
# Fetch the result and store it in a Pandas dataframe
result = cursor.fetchall()
df = pd.DataFrame(result, columns=["city", "avg_salary"])
# Plot the data
plt.bar(df["city"], df["avg_salary"])
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 l.city, AVG(e.salary) as avg_salary " \
"FROM employees e " \
"JOIN locations l ON e.location_id = l.location_id " \
"GROUP BY l.city"
cursor.execute(query)
# Fetch the result and store it in a Pandas dataframe
result = cursor.fetchall()
df = pd.DataFrame(result, columns=["city", "avg_salary"])
# Plot the data
plt.bar(df["city"], df["avg_salary"])
plt.xlabel("Город")
plt.ylabel("Средняя зарплата")
plt.title("Средняя зарплата по городу")
plt.show()
# Close the cursor and connection
cursor.close()
conn.close()