Добавил:
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 / BD_KR2
.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
cursor = cnx.cursor()
# Execute the query
query = '''
SELECT gender, COUNT(*) as count
FROM passangers
GROUP BY gender
'''
cursor.execute(query)
# Fetch the results
results = cursor.fetchall()
# Create two lists to hold the values
labels = []
sizes = []
# Iterate through the results
for result in results:
labels.append(result[0])
sizes.append(result[1])
# Plot the pie chart
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.axis('equal')
plt.show()
# Close the cursor and connection
cursor.close()
cnx.close()
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
cursor = cnx.cursor()
# Execute the query
query = '''
SELECT gender, COUNT(*) as count
FROM passangers
GROUP BY gender
'''
cursor.execute(query)
# Fetch the results
results = cursor.fetchall()
# Create two lists to hold the values
labels = []
sizes = []
# Iterate through the results
for result in results:
labels.append(result[0])
sizes.append(result[1])
# Plot the pie chart
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.axis('equal')
plt.show()
# Close the cursor and connection
cursor.close()
cnx.close()