Добавил:
t.me Инфо для ГУАП студентов от меня: https://kafaka.notion.site/99e6d9b70ca74f7baef3daea17839e5a Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
13
Добавлен:
24.10.2023
Размер:
790 б
Скачать
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()
Соседние файлы в папке Python