<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 PyDrill Demonstration
This notebook demonstrates how to use the PyDrill module to connect to Apache Drill and query data. The complete documentation for PyDrill can be found at http
Step1:  Step 2
Step2:  Step 3
Step3:  Retrieving a DataFrame
You can also get PyDrill to directly return a DataFrame by using the .to_dataframe() method of the results object.
<ASSISTANT_TASK:>
Python Code:
from pydrill.client import PyDrill
Explanation: PyDrill Demonstration
This notebook demonstrates how to use the PyDrill module to connect to Apache Drill and query data. The complete documentation for PyDrill can be found at http://pydrill.readthedocs.io
The essential steps are:
1.  Import the module
2.  Open a connection to Drill
3.  Execute a query
4.  Do something with the results. 
You will first need to install PyDrill.  This can be done by opening a terminal and typing:
python
pip install pydrill
Step 1:  Import the PyDrill module
After you've done this, you will be able to import the PyDrill module.
End of explanation
#Open a connection to Drill
drill = PyDrill(host='localhost', port=8047)
#Verify the connection is active, throw an error if not.
if not drill.is_active():
    raise ImproperlyConfigured('Please run Drill first')
Explanation: Step 2:  Open a connection to Drill
The next step is to open a connection to Drill.  Once you've opened the connection, you will want to verify that the connection was successfully opened before executing any queries.  PyDrill includes an is_active() method for this purpose.
End of explanation
#Execute query in Drill
query_result = drill.query('''
 SELECT JobTitle, 
AVG( CAST( LTRIM( AnnualSalary, '$' ) AS FLOAT) ) AS avg_salary, 
COUNT( DISTINCT name ) AS number
FROM dfs.drillworkshop.`*.csvh`
GROUP BY JobTitle
Order By avg_salary DESC
LIMIT 10
''')
#Iterate through the rows.
for row in query_result:
    print( row )
Explanation: Step 3: Execute a query and get the results
The next and final step is to execute a query in Drill.  When you call the .query() method, PyDrill returns an iterable object from which you can extract the rows of your results.  You can also get PyDrill to return a pandas DataFrame.
End of explanation
df = query_result.to_dataframe()
df.head()
Explanation: Retrieving a DataFrame
You can also get PyDrill to directly return a DataFrame by using the .to_dataframe() method of the results object.
End of explanation
<END_TASK>