<jupyter_start><jupyter_text>*This notebook contains material from [nbpages](https://jckantor.github.io/nbpages) by <NAME> (jeff at nd.edu). The text is released under the[CC-BY-NC-ND-4.0 license](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode).The code is released under the [MIT license](https://opensource.org/licenses/MIT).*<jupyter_code># IMPORT DATA FILES USED BY THIS NOTEBOOK
import os,  requests

file_links = [("data/Stock_Data.csv", "https://jckantor.github.io/nbpages/data/Stock_Data.csv")]

# This cell has been added by nbpages. Run this cell to download data files required for this notebook.

for filepath, fileurl in file_links:
    stem, filename = os.path.split(filepath)
    if stem:
        if not os.path.exists(stem):
            os.mkdir(stem)
    if not os.path.isfile(filepath):
        with open(filepath, 'wb') as f:
            response = requests.get(fileurl)
            f.write(response.content)<jupyter_output><empty_output><jupyter_text>2.4 Working with Data and Figures  2.4.1 Importing dataThe following cell reads the data file `Stock_Data.csv` from the `data` subdirectory. The name of this file will appear in the data index.<jupyter_code>import pandas as pd

df = pd.read_csv("data/Stock_Data.csv")
df.head()<jupyter_output><empty_output><jupyter_text>2.4.2 Creating and saving figuresThe following cell creates a figure `Stock_Data.png` in the `figures` subdirectory. The name of this file will appear in the figures index.<jupyter_code>%matplotlib inline
import os
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("darkgrid")
fig, ax = plt.subplots(2, 1, figsize=(8, 5))
(df/df.iloc[0]).drop('VIX', axis=1).plot(ax=ax[0])
df['VIX'].plot(ax=ax[1])
ax[0].set_title('Normalized Indices')
ax[1].set_title('Volatility VIX')
ax[1].set_xlabel('Days')
fig.tight_layout()

if not os.path.exists("figures"):
    os.mkdir("figures")
plt.savefig("figures/Stock_Data.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13136456211812628, 'fraction_numerical': 0.011710794297352342, 'mean_word_length': 4.779411764705882, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '402', 'license': 'MIT', 'n_tokens_mistral': 699, 'n_tokens_neox': 677, 'n_words': 174, 'path': 'docs/02.04-Working-with-Data-and-Figures.ipynb', 'repo_name': 'jckantor/nbcollection', 'size': '1972'}