Skip to main contentSkip to solution

Arrange the following steps to export DataFrame into MYSQL database.

(A) import pandas and pymysql

(B) Commit changes and close database

(C) Use to_sql() method with appropriate table name and connection

(D) Establish connection to database

Solution

✅ Correct Option: 2

(A) Import pandas and pymysql, so the libraries are available.

(D) Establish the connection to the database.

(C) Use the to_sql() method with the table name and the connection to write the DataFrame.

(B) Commit the changes and close the database.


Options 3 and 4: to_sql() needs an open connection, so (D) must come before (C).

Options 1 and 3: committing and closing must be the last step, after the data is written.

Keyboard Shortcuts

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