Skip to main contentSkip to solution

Arrange the following in order to store data in MySQL from DataFrame:

(A) use to_sql () method

(B) import required libraries

(C) create a DataFrame

(D) create connection with sql alchemy engine

Solution

✅ Correct Option: 3

(B) Import required libraries (pandas and sqlalchemy)

(D) Create the connection with the SQLAlchemy engine

(C) Create a DataFrame

(A) Use the to_sql() method


Options 1, 2 and 4: they place to_sql() before the DataFrame or the engine exists. to_sql() is called on the DataFrame and takes the engine as its connection argument, so it must come last.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question