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
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
(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.
Related questions:
2025: 14 May Shift 1
2026: 29 May Shift 1