Here, we will explain how to operate MySQL with Python.
To register the table saved by csv in MySQL, do as follows.
import pandas as pd
import sqlalchemy as sa
url =Database connection information
engine = sa.create_engine(url)
df = pd.read_csv(file name)
df.to_sql(table name, engine, index=False, if_exists='replace')
By changing ʻif_exists of the
pandas.to_sql method to ʻappend
, it will be added instead of overwritten.
Here, I explained how to add data to MySQL using Python. With SQL Alchemy, you can register data in the database without writing SQL directly.
What is the programming language Python? Can it be used for AI and machine learning?
Recommended Posts