<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pandas and data wrangling
Pandas is a tool for accessing columnar data, like that in SQL tables or CSV files.
Step1:  Let's start by reading in a dataset. This dataset is about different subclasses of the iris flower.
We'll use it for another exercise later on.
Step2:  DataFrame is the basic building block of Pandas. It represents two-dimensional data with labeled rows and columns.
<ASSISTANT_TASK:>
Python Code:
# convention recommended in documentation
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#enable inline plotting in notebook
%matplotlib inline
Explanation: Pandas and data wrangling
Pandas is a tool for accessing columnar data, like that in SQL tables or CSV files.
End of explanation
df = pd.read_csv("../data/iris.data")
df = df.sample(frac=0.2) # only use 20% of the data so the results aren't so long
type(df)
Explanation: Let's start by reading in a dataset. This dataset is about different subclasses of the iris flower.
We'll use it for another exercise later on.
End of explanation
# Columns can have different types.
# you can check the data types of the values
df.dtypes
# you can access the dataframe with a single column name
df["petal.width"]
# this leaves the original unmodified
# then the returned type is a Series, the second major concept in Pandas
type(df["petal.width"])
# 
# alternately you can index a dataframe with a list of column names
df[["sepal.length", "petal.width", "class"]]
# the comparison operator returns a list of boolean 
matching = df["sepal.width"] > df["petal.length"]
matching
# which can also be used to query the dataframe
df[list_]
# or more idiomatically
df[df["sepal.width"] > df["petal.length"]]
# one can get aggregates of single dimensions
df["sepal.width"].var() # try min, max, mean, median, sum, var
# or of the whole thing
df.sum() # same operations as above
# it's also possible to plot simple graphs using a simpleish syntax
df["sepal.width"].plot.box()
df["sepal.width"].plot.hist()
df.boxplot(column="sepal.width", by="class")
df.plot.scatter(x="sepal.length", y="sepal.width")
df.groupby("class").mean()
# creating a grouped by plot requires a loop
fig, ax = plt.subplots(figsize=(8,6))
for label, df_ in df.groupby('class'):
    df_["sepal.length"].plot(kind="kde", ax=ax, label=label)
plt.legend()
Explanation: DataFrame is the basic building block of Pandas. It represents two-dimensional data with labeled rows and columns.
End of explanation
<END_TASK>