<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 title
Step1:  Load the data with Pandas
Print the first five rows of the gapminder DataFrame
What is the average (mean) life expectancy for the entire dataset?
What is the average (mean) life expectancy, for each continent?
For each country in Oceania, print the subset of the data for that country
Sort gapminder by population. Make sure the sorted object replaces the existing gapminder DataFrame
Using seaborn, generate a scatterplot depicting the relationship between population and life expectancy and include a linear best fit line
Step2:  Generate the same graph as above, but this time log-transform the population variable
Write a Function
(To Assess the Relationship Between Year and Life Expectancy for a Given Country)
Here the goal is to write a basic function, "life_expectancy", that incorporates your work above. 
By default, the function should return a scatterplot of life-expectancy versus years for a given country. 
[Hint
Step3:  Example Results for the Function
Your function should be able to produce these results
<ASSISTANT_TASK:>
Python Code:
# Import libraries
import pandas as pd
import numpy as np
# Turn off notebook package warnings
import warnings
warnings.filterwarnings('ignore')
# print graphs in the document
%matplotlib inline
Explanation: title: "Homework 05: Analyzing the gapminder dataset using Python"
output: html_document
Overview
Due before class Wednesday November 2nd.
The basic goal of the assignment is to implement various computational methods (e.g. data frames, lists, filtering, conditional expressions, iteration, functions) in Python. Rather than using raw programming assignments, you will demonstrate these skills in the context of analyzing the gapminder dataset, something you have already explored in R.
Fork the hw05 repository
Go here to fork the repo for homework 05.
Workflow
You are provided with a Jupyter Notebook similar to the one seen here. Fill in the chunks with the appropriate code needed to perform the requested analysis. I have already identified the questions and tasks you need to perform.
Submit the assignment
Your assignment should be submitted as a single Jupyter Notebook. Follow instructions on homework workflow. As part of the pull request, you're encouraged to reflect on what was hard/easy, problems you solved, helpful tutorials you read, etc.
Rubric
Check minus: Notebook cannot be run. Didn't answer all of the questions. Code is incomprehensible or difficult to follow.
Check: Solid effort. Hits all the elements. No clear mistakes. Easy to follow (both the code and the output). Nothing spectacular, either bad or good.
Check plus: Innovative use of coding elements to solve the problems (e.g. functions, conditional expressions, iterations). Adds labels to graphs. Uses techniques beyond those from the example notebooks. Successfully attempts the advanced challenge.
Import packages and setup the notebook
End of explanation
import seaborn as sns
Explanation: Load the data with Pandas
Print the first five rows of the gapminder DataFrame
What is the average (mean) life expectancy for the entire dataset?
What is the average (mean) life expectancy, for each continent?
For each country in Oceania, print the subset of the data for that country
Sort gapminder by population. Make sure the sorted object replaces the existing gapminder DataFrame
Using seaborn, generate a scatterplot depicting the relationship between population and life expectancy and include a linear best fit line
End of explanation
import statsmodels.formula.api as sm #Import Package
model = sm.ols(formula = 'lifeExp ~ year', data = gapminder).fit() #Fit OLS Model
results = model.summary() #Get Results
print(results) # Print
#Hint: Use this Code in Your Function. 
#You will need to replace data = gapminder, with the data subset for a specific country.
# write your function here
Explanation: Generate the same graph as above, but this time log-transform the population variable
Write a Function
(To Assess the Relationship Between Year and Life Expectancy for a Given Country)
Here the goal is to write a basic function, "life_expectancy", that incorporates your work above. 
By default, the function should return a scatterplot of life-expectancy versus years for a given country. 
[Hint: Subset the data for a specific country, similar to a problem above]
Once you subset the data, the function should do one of two things: 
* (1) return a graph [or]
* (2) return a graph and model results. 
Thus, your function should have arguments and output as follows:
```
*   Arguments:
        Country (required):   The name of a specific country, such as "Australia"
        Model   (optional):   Build and Return a Model Results, #Hint, set the default to be False
Output: 
        (1) - Default: A scatterplot of the relationship with best fit line
        (2) - Model:   The above graph AND the model results
```
Of course, we have not yet covered modeling in Python.
To run a linear model, we can use the library statsmodels, to predict life expectancy by year.
Example for this problem:
End of explanation
# Result for a Country (No Model)
life_expectancy("Afghanistan")
# Result for a Country (Model = True)
life_expectancy("New Zealand", True)
Explanation: Example Results for the Function
Your function should be able to produce these results:
End of explanation
<END_TASK>