<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 What is Pandas?
Pandas provides fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive.
Numpy/Scipy/astropy.tables provide ways to store + manipulate data, but sometimes you have to hack things together when using those libraries.  Pandas makes those interactions more straightforward.  In my experience, the simplicity of working with Pandas helps keep code maintainable and understandable. 
Where can I see some other examples of Pandas?
10 Minutes to Pandas (their tutorial)
Jake VanderPlas's blog
Numpy example
Step1:  data is now a "structured" numpy array.  We can access it like a normal 2d array
Step2:  but we can also access columns using their names
Step3:  And we can work with these columns just like a standard numpy array
Step4:  But what happens if we try to add new columns? It'd be nice if it behaved like a dict
Step5:  Okay. That's not a huge problem. There are alternatives, but it can be ugly.
Let's try separating our data into subsets, and plotting.  It's not bad, but also not great.
Step6:  Pandas version
Let's do some of the same things, except now using a pandas.DataFrame.
A DataFrame is like an extension of a structured array, but with more features.
Step7:  Similar to astropy tables, DataFrames have nice ways display an overview of the data
Step8:  We can access columns through their names (like with structured arrays) or we can access columns as an object attribute
Step9:  We can add new columns
Step10:  It also provides nice wrapper functions for visualizing an entire dataset
Step11:  We can create groups based on the values of a column
Step12:  And we can plot using these groups. It's much less verbose than when we did it in numpy
Step13:  You can also do fancier plots. But sometimes the defaults aren't very pretty (e.g. the plots below are missing x-axis labels, and aren't labeled by cut).
But if you want to see better ways to use pandas with plotting, check out
Step14:  Pandas with SQL Databases
If you work with databases, you might notice that a DataFrame is similar to a table.
This makes it (somewhat) easy to interface with a table in an existing database.  Here I'll read in an existing table directly to a DataFrame
Step15:  Time Domain
Pandas was also developed with time domain applications in mind, so it includes some extra power for dealing with DateTimes.
Step16:  Let's take the average weekly temperature (resample on a weekly timescale)
Step17:  That's an ugly plot. It'd be nicer if we just smooth the plot, instead of down-sampling
<ASSISTANT_TASK:>
Python Code:
url = "https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/ggplot2/diamonds.csv"
data = np.genfromtxt(url, delimiter=",", dtype=None, names=True)
data
Explanation: What is Pandas?
Pandas provides fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive.
Numpy/Scipy/astropy.tables provide ways to store + manipulate data, but sometimes you have to hack things together when using those libraries.  Pandas makes those interactions more straightforward.  In my experience, the simplicity of working with Pandas helps keep code maintainable and understandable. 
Where can I see some other examples of Pandas?
10 Minutes to Pandas (their tutorial)
Jake VanderPlas's blog
Numpy example
End of explanation
data[0][2]
Explanation: data is now a "structured" numpy array.  We can access it like a normal 2d array:
End of explanation
data[0]["cut"]
Explanation: but we can also access columns using their names:
End of explanation
data["price"].mean()
Explanation: And we can work with these columns just like a standard numpy array
End of explanation
data["price_per_carat"] = data["price"] / data["carat"]
Explanation: But what happens if we try to add new columns? It'd be nice if it behaved like a dict
End of explanation
cuts = set(data["cut"])
for cut in cuts:
    plt.figure()
    plt.title(cut.decode())
    plt.hist(data[data["cut"]==cut]["price"])
Explanation: Okay. That's not a huge problem. There are alternatives, but it can be ugly.
Let's try separating our data into subsets, and plotting.  It's not bad, but also not great.
End of explanation
url = 'https://github.com/vincentarelbundock/Rdatasets/raw/master/csv/ggplot2/diamonds.csv'
df = pd.read_csv(url, index_col=0)
type(df)
Explanation: Pandas version
Let's do some of the same things, except now using a pandas.DataFrame.
A DataFrame is like an extension of a structured array, but with more features.
End of explanation
df.head()
df.describe()
Explanation: Similar to astropy tables, DataFrames have nice ways display an overview of the data:
End of explanation
df["price"].std()
df.price.max()
Explanation: We can access columns through their names (like with structured arrays) or we can access columns as an object attribute
End of explanation
df["price_per_carat"] = df["price"] / df.carat
Explanation: We can add new columns:
End of explanation
df.hist(figsize=(15,15))
Explanation: It also provides nice wrapper functions for visualizing an entire dataset:
End of explanation
df.groupby("cut").price.std()
Explanation: We can create groups based on the values of a column:
End of explanation
df.hist(column="price", by="cut", figsize=(20,20))
Explanation: And we can plot using these groups. It's much less verbose than when we did it in numpy
End of explanation
df.groupby("cut").plot.hexbin("price", "carat", gridsize=20, title="")
Explanation: You can also do fancier plots. But sometimes the defaults aren't very pretty (e.g. the plots below are missing x-axis labels, and aren't labeled by cut).
But if you want to see better ways to use pandas with plotting, check out:
http://pandas.pydata.org/pandas-docs/stable/visualization.html
End of explanation
df_from_table = pd.read_sql_table("status", "sqlite:///sample_database.db")
df_from_table = df_from_table.set_index("id")
df_from_table.head()
df_from_table[df_from_table["status"] == "Running"]
df_from_table.loc["cb33250c-7c9a-490a-be79-903e8bb8e338"]
Explanation: Pandas with SQL Databases
If you work with databases, you might notice that a DataFrame is similar to a table.
This makes it (somewhat) easy to interface with a table in an existing database.  Here I'll read in an existing table directly to a DataFrame
End of explanation
url = "http://mesonet.agron.iastate.edu/cgi-bin/request/asos.py?station=WVI&data=tmpf&year1=2014&month1=1&day1=1&year2=2014&month2=12&day2=31&tz=America%2FLos_Angeles&format=comma&latlon=no&direct=no"
df = pd.read_csv(url, 
            comment="#", 
            names=["Station", "Time", "Temp"], 
            parse_dates=True,
            header=1, 
            na_values="M",
            index_col="Time")
df.head()
df.plot()
Explanation: Time Domain
Pandas was also developed with time domain applications in mind, so it includes some extra power for dealing with DateTimes.
End of explanation
df.resample("w").plot()
Explanation: Let's take the average weekly temperature (resample on a weekly timescale):
End of explanation
pd.rolling_mean(df, freq="d", window=7).plot()
Explanation: That's an ugly plot. It'd be nicer if we just smooth the plot, instead of down-sampling
End of explanation
<END_TASK>