<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 CSE 6040, Fall 2015 [08]
Step1:  Create Data
The data set will consist of 5 baby names and the number of births recorded for that year (1880).
Step2:  To merge these two lists together we will use the zip function.
Step3:  We are basically done creating the data set. We now will use the pandas library to export this data set into a csv file.
We will create a DataFrame object. You can think of this object holding the contents of the BabyDataSet in a format similar to an excel spreadsheet.
Step4:  Export the dataframe to a csv file. We can name the file births1880.csv. The function to_csv will be used to export the file. The file will be saved in the same location of the notebook unless specified otherwise.
Step5:  Get Data
To pull in the csv file, we will use the pandas function read_csv. Let us take a look at this function and what inputs it takes.
Step6:  This brings us the our first problem of the exercise. The read_csv function treated the first record in the csv file as the header names. This is obviously not correct since the text file did not provide us with header names.  
To correct this we will pass the header parameter to the read_csv function and set it to None (means null in python).
Step7:  If we wanted to give the columns specific names, we would have to pass another paramter called names. We can also omit the header parameter.
Step8:  It is also possible to read in a csv file by passing an url address
Here we use the famous Iris dataset.
The data set consists of 50 samples from each of three species of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features were measured from each sample
Step9:  Analyze Data
Step10:  We can get the maximum sepal length by
Step11:  If we want to find full information of the flower with maximum sepal length
Step12:  Exercise
Print the full information of the flower whose petal length is the second shortest in the 50 Iris-setosa flowers
Step13:  Pandas also has some basic plotting functions.
Step14:  Part 2
Step15:  Plotting univariate distributions
distplot() function will draw a histogram and fit a kernel density estimate
Step16:  Plotting bivariate distributions
Step17:  Scatter plot
Step18:  Hexbin plot
Step19:  Kernel density estimation
Step20:  Visualizing pairwise relationships in a dataset
To plot multiple pairwise bivariate distributions in a dataset, you can use the pairplot() function. This creates a matrix of axes and shows the relationship for each pair of columns in a DataFrame. by default, it also draws the univariate distribution of each variable on the diagonal Axes
Step21:  Visualizing linear relationships
Step22:  We can use the function regplot to show the linear relationship between total_bill and tip. 
It also shows the 95% confidence interval.
Step23:  Visualizing higher order relationships
Step24:  The plot clearly shows that this is not a good model.
Let's try to fit a polynomial regression model with degree 2.
Step25:  Strip mplots
This is similar to scatter plot but used when one variable is categorical.
Step26:  Boxplots
Step27:  Bar plots
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
Explanation: CSE 6040, Fall 2015 [08]: Data analysis and visualization
In todays class, we will first introduce a data analysis tools called Pandas,
and then show how to visualize the data using a module called Seaborn.
Most of the examples come from 
Pandas tutorial
and
Seaborn tutorial.
Part 1: Data analysis using Pandas
Pandas is pre-installed with Anaconda. 
Let's try to import it.
End of explanation
# The inital set of baby names and bith rates
names = ['Bob','Jessica','Mary','John','Mel']
births = [968, 155, 77, 578, 973]
Explanation: Create Data
The data set will consist of 5 baby names and the number of births recorded for that year (1880).
End of explanation
BabyDataSet = zip(names,births)
BabyDataSet
Explanation: To merge these two lists together we will use the zip function.
End of explanation
df = pd.DataFrame(data = BabyDataSet, columns=['Names', 'Births'])
df
Explanation: We are basically done creating the data set. We now will use the pandas library to export this data set into a csv file.
We will create a DataFrame object. You can think of this object holding the contents of the BabyDataSet in a format similar to an excel spreadsheet.
End of explanation
df.to_csv('births1880.csv',index=False,header=False)
Explanation: Export the dataframe to a csv file. We can name the file births1880.csv. The function to_csv will be used to export the file. The file will be saved in the same location of the notebook unless specified otherwise.
End of explanation
df = pd.read_csv("births1880.csv")
df
Explanation: Get Data
To pull in the csv file, we will use the pandas function read_csv. Let us take a look at this function and what inputs it takes.
End of explanation
df = pd.read_csv("births1880.csv", header=None)
df
Explanation: This brings us the our first problem of the exercise. The read_csv function treated the first record in the csv file as the header names. This is obviously not correct since the text file did not provide us with header names.  
To correct this we will pass the header parameter to the read_csv function and set it to None (means null in python).
End of explanation
df = pd.read_csv("births1880.csv", names=['Names','Births'])
df
Explanation: If we wanted to give the columns specific names, we would have to pass another paramter called names. We can also omit the header parameter.
End of explanation
df = pd.read_csv("https://raw.githubusercontent.com/bigmlcom/bigmler/master/data/iris.csv")
df.head(10)
Explanation: It is also possible to read in a csv file by passing an url address
Here we use the famous Iris dataset.
The data set consists of 50 samples from each of three species of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features were measured from each sample: the length and the width of the sepals and petals.
End of explanation
# show basic statistics
df.describe()
# Select a column
df["sepal length"].head()
# select columns
df[["sepal length", "petal width"]].head()
# select rows by name
df.loc[5:10]
# select rows by position
df.iloc[5:10]
# select rows by condition
df[df["sepal length"] > 5.0]
Explanation: Analyze Data
End of explanation
df["sepal length"].max()
Explanation: We can get the maximum sepal length by
End of explanation
df.sort("sepal length", ascending=False).head(1)
Explanation: If we want to find full information of the flower with maximum sepal length
End of explanation
df.sort("petal length", ascending=True)
df.iloc[1]
Explanation: Exercise
Print the full information of the flower whose petal length is the second shortest in the 50 Iris-setosa flowers
End of explanation
import matplotlib.pyplot as plt
%matplotlib inline
df.hist()
Explanation: Pandas also has some basic plotting functions.
End of explanation
import seaborn as sns
# make the plots to show right below the codes
% matplotlib inline
Explanation: Part 2: Visualization using Seaborn
Seaborn is not installed by default in Anaconda.
Try install it using pip: pip install seaborn.
End of explanation
import numpy as np
x = np.random.normal(size=100)
sns.distplot(x)
import random
x = [random.normalvariate (0, 1) for i in range (0, 1000)]
sns.distplot (x)
Explanation: Plotting univariate distributions
distplot() function will draw a histogram and fit a kernel density estimate
End of explanation
mean, cov = [0, 1], [(1, .5), (.5, 1)]
data = np.random.multivariate_normal(mean, cov, 200)
df = pd.DataFrame(data, columns=["x", "y"])
Explanation: Plotting bivariate distributions
End of explanation
sns.jointplot(x="x", y="y", data=df)
Explanation: Scatter plot
End of explanation
sns.jointplot(x="x", y="y", data=df, kind="hex")
Explanation: Hexbin plot
End of explanation
sns.jointplot(x="x", y="y", data=df, kind="kde")
Explanation: Kernel density estimation
End of explanation
iris = sns.load_dataset("iris")
sns.pairplot(iris)
# we can add colors to different species
sns.pairplot(iris, hue="species")
Explanation: Visualizing pairwise relationships in a dataset
To plot multiple pairwise bivariate distributions in a dataset, you can use the pairplot() function. This creates a matrix of axes and shows the relationship for each pair of columns in a DataFrame. by default, it also draws the univariate distribution of each variable on the diagonal Axes:
End of explanation
tips = sns.load_dataset("tips")
tips.head()
Explanation: Visualizing linear relationships
End of explanation
sns.regplot(x="total_bill", y="tip", data=tips)
Explanation: We can use the function regplot to show the linear relationship between total_bill and tip. 
It also shows the 95% confidence interval.
End of explanation
anscombe = sns.load_dataset("anscombe")
sns.regplot(x="x", y="y", data=anscombe[anscombe["dataset"] == "II"])
Explanation: Visualizing higher order relationships
End of explanation
sns.regplot(x="x", y="y", data=anscombe[anscombe["dataset"] == "II"], order=2)
Explanation: The plot clearly shows that this is not a good model.
Let's try to fit a polynomial regression model with degree 2.
End of explanation
sns.stripplot(x="day", y="total_bill", data=tips)
Explanation: Strip mplots
This is similar to scatter plot but used when one variable is categorical.
End of explanation
sns.boxplot(x="day", y="total_bill", hue="time", data=tips)
Explanation: Boxplots
End of explanation
titanic = sns.load_dataset("titanic")
sns.barplot(x="sex", y="survived", hue="class", data=titanic)
Explanation: Bar plots
End of explanation
<END_TASK>