Добавил:
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 / LR1_Q1
.py import mysql.connector
import matplotlib.pyplot as plt
# Connect to the database
cnx = mysql.connector.connect(
host='127.0.0.1',
user='root',
password='admin',
database='airport'
)
# Create a cursor object
cursor = cnx.cursor()
# Define the query
query = "SELECT dep_city, des_city, count(*) as flight_count FROM flights GROUP BY dep_city, des_city ORDER BY flight_count DESC"
# Execute the query
cursor.execute(query)
# Fetch the results
results = cursor.fetchall()
# Print the results
for result in results:
print(result)
# Close the cursor and connection
cursor.close()
cnx.close()
# Get the top 10 results
top_5_results = results[:5]
# Extract the labels and values for the chart
labels = [f"{result[0]}-{result[1]}" for result in top_5_results]
values = [result[2] for result in top_5_results]
# Create the bar chart
plt.bar(labels, values)
plt.xlabel("Departure-Destination City Pair")
plt.ylabel("Flight Count")
plt.title("Top 5 Departure-Destination City Pairs by Flight Count")
# Show the chart
plt.show()
import matplotlib.pyplot as plt
# Connect to the database
cnx = mysql.connector.connect(
host='127.0.0.1',
user='root',
password='admin',
database='airport'
)
# Create a cursor object
cursor = cnx.cursor()
# Define the query
query = "SELECT dep_city, des_city, count(*) as flight_count FROM flights GROUP BY dep_city, des_city ORDER BY flight_count DESC"
# Execute the query
cursor.execute(query)
# Fetch the results
results = cursor.fetchall()
# Print the results
for result in results:
print(result)
# Close the cursor and connection
cursor.close()
cnx.close()
# Get the top 10 results
top_5_results = results[:5]
# Extract the labels and values for the chart
labels = [f"{result[0]}-{result[1]}" for result in top_5_results]
values = [result[2] for result in top_5_results]
# Create the bar chart
plt.bar(labels, values)
plt.xlabel("Departure-Destination City Pair")
plt.ylabel("Flight Count")
plt.title("Top 5 Departure-Destination City Pairs by Flight Count")
# Show the chart
plt.show()