## Jupyter Snippet CB2nd 02_pandas

Jupyter Snippet CB2nd 02_pandas

# 1.2. Getting started with exploratory data analysis in the Jupyter Notebook

``````import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
``````
``````url = ("https://raw.githubusercontent.com/"
"ipython-books/cookbook-2nd-data/"
"master/bikes.csv")
``````
``````df = pd.read_csv(url, index_col='Date',
parse_dates=True, dayfirst=True)
``````
``````df.head(2)
``````

``````df.describe()
``````

``````df[['Berri1', 'PierDup']].plot(figsize=(10, 6),
style=['-', '--'],
lw=2)
``````

``````df.index.weekday_name
``````
``````Index(['Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday', 'Monday', 'Tuesday',
...
'Friday', 'Saturday', 'Sunday', 'Monday',
'Tuesday', 'Wednesday'],
dtype='object', name='Date', length=261)
``````
``````df_week = df.groupby(df.index.weekday).sum()
``````
``````df_week
``````

``````fig, ax = plt.subplots(1, 1, figsize=(10, 8))
df_week.plot(style='-o', lw=3, ax=ax)
ax.set_xlabel('Weekday')
# We replace the labels 0, 1, 2... by the weekday
# names.
ax.set_xticklabels(
('Monday,Tuesday,Wednesday,Thursday,'
'Friday,Saturday,Sunday').split(','))
ax.set_ylim(0)  # Set the bottom axis to 0.
``````

``````from ipywidgets import interact

@interact
def plot(n=(1, 30)):
fig, ax = plt.subplots(1, 1, figsize=(10, 8))
df['Berri1'].rolling(window=n).mean().plot(ax=ax)
ax.set_ylim(0, 7000)
plt.show()
``````