Last answered:

29 May 2023

Posted on:

26 May 2023


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)


However I am facing one problem in the end . DF is not defined. Thx in advance for your help.


1 answers ( 0 marked as helpful)
Posted on:

29 May 2023


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.

Submit an answer