CBSE Class 12 Informatics Practices Question 63 of 70

Importing/Exporting Data between CSV Files/MySQL and Pandas — Question 7

Back to all questions
7
Question

Question 7

Consider following code when conn is the name of established connection to MySQL database.

sql = SELECT * from Sales where zone = "central"; 
df = pandas.read_sql(sql, conn)
df.head()

What will be stored in df ?

Answer

The DataFrame df includes all the columns where 'zone' equals 'central'.

Explanation

The code executes an SQL query to select all columns (*) from the "Sales" table where the "zone" column equals to "central". It then reads the results of the query into a pandas DataFrame df using pandas.read_sql(). Then, it returns the first five rows of df using df.head().