Answers for "python pandas work with database"

2

read database pandas

from sqlalchemy import create_engine

engine = create_engine("sqlite:///data.db")

query = """
SELECT * 
  FROM weather;
"""

weather = pd.read_sql(query, engine)
Posted by: Guest on July-10-2021
1

working with mysql database in pandas

Importing data from a MySQL database into a Pandas data frame including column names:-
import mysql.connector as sql.
import pandas as pd.
db_connection = sql.connect(host='hostname', database='db_name', user='username', password='password')
db_cursor = db_connection.cursor()
db_cursor.execute('SELECT * FROM table_name')
Posted by: Guest on January-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language