> For the complete documentation index, see [llms.txt](https://ondrej-kvasnovsky-2.gitbook.io/handbook-of-hidden-data-scientist-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ondrej-kvasnovsky-2.gitbook.io/handbook-of-hidden-data-scientist-python/chapter1/plot-csv-data.md).

# Plot and Normalize CSV Data

## Plot and Normalize CSV Data

Create CSV file with the following content and name it "AAPL.csv". It contains stock information for few days. You can get more data on [https://finance.yahoo.com/quote/AAPL/history?p=AAPL. ](https://finance.yahoo.com/quote/AAPL/history?p=AAPL)

```
Date,Open,High,Low,Close,Volume,Adj Close
2017-01-20,120.449997,120.449997,119.730003,120.00,29479900,120.00
2017-01-19,119.400002,120.089996,119.370003,119.779999,25295700,119.779999
2017-01-18,120.00,120.50,119.709999,119.989998,23644700,119.989998
2017-01-17,118.339996,120.239998,118.220001,120.00,34078600,120.00
2017-01-13,119.110001,119.620003,118.809998,119.040001,25938300,119.040001
2017-01-12,118.900002,119.300003,118.209999,119.25,27002400,119.25
2017-01-11,118.739998,119.93,118.599998,119.75,27418600,119.75
```

## Plot data

REad AAPL.csv file and pick 'Close' and 'Adj Close' column to plot. Then show the plot.

```
import pandas as pd
import matplotlib.pyplot as plt

def test_run():
    df = pd.read_csv("data/AAPL.csv")
    df[['Close', 'Adj Close']].plot()
    plt.show()

if __name__ == "__main__":
    test_run()
```

Here is the output.

![](/files/-M3wY5nGHkFuDrSWth8u)

## Normalize data

We need normalize data in order to have all the values starting from the same point, so we can measure difference easily.

```
import pandas as pd
import matplotlib.pyplot as plt

def test_run():
    df = pd.read_csv("data/AAPL.csv")
    twoColumnsDf = df[['Close', 'Adj Close']]
    twoColumnsDf = normalize_data(twoColumnsDf)
    twoColumnsDf.plot()
    plt.show()

def normalize_data(df):
    return df / df.ix[0, :]

if __name__ == "__main__":
    test_run()
```

Here is the output. Now you can see how stocks differ from each other because both lines start from 1. Better example would be to compare 'Adj Close' for multiple datasets (like AAPL, GOOG, GLD, etc.).

![](/files/-M3wY5nITcq1NpvrM0-n)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/handbook-of-hidden-data-scientist-python/chapter1/plot-csv-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
