Convert CSV file to MYSQL
Hello, how are you doing guys? I am using your annual premium subscription . May you please help to convert file from csv to mysql. I am trying to use what I found online
I am going through python.
Here is the code:
import pandas as pd
import glob, os
from sqlalchemy import create_engine
for file in glob.glob("*.csv"):
df = pd.read_csv(file)
# Create SQLAlchemy engine to connect to MySQL Database
engine = create_engine("mysql+mysqldb://root:<PASSWORD>@localhost:3306/airbnb")
# Convert dataframe to sql table
df.to_sql(file[:-4], engine, index=False)
print('done')
However I am facing one problem in the end . DF is not defined. Thx in advance for your help.
Regards,
Artur
Hi Artur!
Thanks for reaching out.
This error message means that you have not executed the cell where this variable is defined. You should execute the cells in a consecutive way.
Hope this helps.
Best,
Tsvetelin