pip install sqlalchemy
import pandas as pd
from sqlalchemy import create_engine
# Establish a connection to the MySQL database using SQLAlchemy
engine = create_engine('mysql+mysqlconnector://root:root@localhost/test')
# Define your SQL query
query = "SELECT * FROM users"
# Load data from the MySQL database into a pandas DataFrame
df = pd.read_sql(query, con=engine)
# Close the database connection
engine.dispose()
# Display the DataFrame
print(df)
Python