<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Sparklines in Pandas
Sparklines are small unlabeled plots, used to visually convey an idea in a small space.  This script creates sparklines in a Pandas DataFrame which can then be displayed inline in a Jupyter Notebook or output to an HTML file.  It does not annotate the figure, other columns of the DataFrame can be used to convey details about the sparklines.
Background
Step1:  Create some plot data
Function assumes data to plot is an array-like object in a single cell per row.
Step2:  Define range of data to make sparklines
Note
Step3:  Output to new DataFrame of Sparklines
Step4:  Insert Sparklines into source DataFrame
Step5:  Detailed Formatting
Return only sparklines, format the line, fill and marker.
Step6:  Example Data and Sparklines Layout
Step7:  Export to HTML
Inline Jupyter Notebook
Step8:  HTML text for rendering elsewhere
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
%matplotlib inline
import sparklines
Explanation: Sparklines in Pandas
Sparklines are small unlabeled plots, used to visually convey an idea in a small space.  This script creates sparklines in a Pandas DataFrame which can then be displayed inline in a Jupyter Notebook or output to an HTML file.  It does not annotate the figure, other columns of the DataFrame can be used to convey details about the sparklines.
Background:
https://en.wikipedia.org/wiki/Sparkline
Forked and extended from:
https://github.com/iiSeymour/sparkline-nb
End of explanation
density_func = 78
mean, var, skew, kurt = stats.chi.stats(density_func, moments='mvsk')
x_chi = np.linspace(stats.chi.ppf(0.01, density_func),
                    stats.chi.ppf(0.99, density_func), 100)
y_chi = stats.chi.pdf(x_chi, density_func)
x_expon = np.linspace(stats.expon.ppf(0.01), stats.expon.ppf(0.99), 100)
y_expon = stats.expon.pdf(x_expon)
a_gamma = 1.99
x_gamma = np.linspace(stats.gamma.ppf(0.01, a_gamma),
                      stats.gamma.ppf(0.99, a_gamma), 100)
y_gamma = stats.gamma.pdf(x_gamma, a_gamma)
n = 100
np.random.seed(0)  # keep generated data the same for git commit
data = [np.random.rand(n), 
        np.random.randn(n), 
        np.random.beta(2, 1, size=n), 
        np.random.binomial(3.4, 0.22, size=n), 
        np.random.exponential(size=n),
        np.random.geometric(0.5, size=n), 
        np.random.laplace(size=n), 
        y_chi, 
        y_expon, 
        y_gamma]
function = ['rand',
            'randn',
            'beta',
            'binomial',
            'exponential',
            'geometric',
            'laplace',
            'chi',
            'expon',
            'gamma']
df = pd.DataFrame(data)
df['function'] = function
df
Explanation: Create some plot data
Function assumes data to plot is an array-like object in a single cell per row.
End of explanation
a = df.ix[:, 0:100]
Explanation: Define range of data to make sparklines
Note: data must be row wise
End of explanation
df_out = pd.DataFrame()
df_out['sparkline'] = sparklines.create(data=a)
sparklines.show(df_out[['sparkline']])
Explanation: Output to new DataFrame of Sparklines
End of explanation
df['sparkline'] = sparklines.create(data=a)
sparklines.show(df[['function', 'sparkline']])
Explanation: Insert Sparklines into source DataFrame
End of explanation
df_out = pd.DataFrame()
df_out['sparkline'] = sparklines.create(data=a,
                                        color='#1b470a',
                                        fill_color='#99a894',
                                        fill_alpha=0.2,
                                        point_color='blue',
                                        point_fill='none',
                                        point_marker='*',
                                        point_size=3,
                                        figsize=(6, 0.25))
sparklines.show(df_out[['sparkline']])
Explanation: Detailed Formatting
Return only sparklines, format the line, fill and marker.
End of explanation
df_copy = df[['function', 'sparkline']].copy()
df_copy['value'] = df.ix[:, 100]
df_copy['change'] = df.ix[:,98] - df.ix[:,99]
df_copy['change_%'] = df_copy.change / df.ix[:,99]
sparklines.show(df_copy)
Explanation: Example Data and Sparklines Layout
End of explanation
sparklines.to_html(df_copy, 'pandas_sparklines_demo')
Explanation: Export to HTML
Inline Jupyter Notebook
End of explanation
html = sparklines.to_html(df_copy)
Explanation: HTML text for rendering elsewhere
End of explanation
<END_TASK>