> For the complete documentation index, see [llms.txt](https://larhues-personal-organization.gitbook.io/intro-to-data-visualization/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://larhues-personal-organization.gitbook.io/intro-to-data-visualization/exercises-and-examples/stock-market/understanding-boeing-data-over-time.md).

# Understanding Boeing Data Over Time

There are many different visualizations to explore how Boeing Stock price changed in 2024. Let's explore and compare these visualizations.

### Daily values - Line Chart

First, let's create a line chart with the daily values of Boeing stock prices for 2024.

```python
import pandas as pd
import yfinance as yf
import kaleido
import plotly.express as px
import plotly.io as pio

# Download boeing data for 2024 and flatten the index
start = '2024-01-01'
end = '2024-12-31'
boeing = yf.download('BA', start=start, end=end, interval='1d')
boeing.reset_index(inplace=True)
boeing.columns = boeing.columns.to_flat_index()
boeing.columns = ['_'.join(col) for col in boeing.columns]
boeing.columns = ["Date", "Close", "High", "Low", "Open", "Volume"] # rename columns

# Create the visualization
fig = px.bar(boeing, x="Date", y="Close", color_discrete_sequence=["black"]) 

# Show the image
fig.show()

# Save the image
pio.write_image(fig, "boeing_daily_bar.png", engine="kaleido")
```

<figure><img src="/files/4jthJ5DkMltOzALgsJOc" alt=""><figcaption></figcaption></figure>

### Daily values - Bar chart

Next, let's create a line chart with the daily values of Boeing stock prices for 2024. How does this chart compare to the previous chart?

```python
import pandas as pd
import yfinance as yf
import kaleido
import plotly.express as px
import plotly.io as pio

# Download boeing data for 2024 and flatten the index
start = '2024-01-01'
end = '2024-12-31'
boeing = yf.download('BA', start=start, end=end, interval='1d')
boeing.reset_index(inplace=True)
boeing.columns = boeing.columns.to_flat_index()
boeing.columns = ['_'.join(col) for col in boeing.columns]
boeing.columns = ["Date", "Close", "High", "Low", "Open", "Volume"] # rename columns

# Create the visualization
fig = px.bar(boeing, x="Date", y="Close", color_discrete_sequence=["black"]) 

# Show the image
fig.show()

# Save the image
pio.write_image(fig, "boeing_daily_bar.png", engine="kaleido")
```

<figure><img src="/files/oOG2lVuGVROIM5HEILSa" alt=""><figcaption></figcaption></figure>

### Monthly values - Line Chart

Third, we change the granularity of the data. Let's create a visualization of the monthly changes in the Boeing stock price. How does this chart compare to the previous two charts?

```python
import pandas as pd
import yfinance as yf
import kaleido
import plotly.express as px
import plotly.io as pio

# Download boeing data for 2024 and flatten the index
# interval = '1mo' for monthly data
start = '2024-01-01' #start date for download
end = '2024-12-31' # end date for download
boeing = yf.download('BA', start=start, end=end, interval='1mo') 
boeing.reset_index(inplace=True)
boeing.columns = boeing.columns.to_flat_index()
boeing.columns = ['_'.join(col) for col in boeing.columns]
boeing.columns = ["Date", "Close", "High", "Low", "Open", "Volume"] # rename columns

# Create the visualization with black bars
fig = px.line(boeing, x="Date", y="Close", color_discrete_sequence=["black"]) 

# Show the image
fig.show()

# Save the image
pio.write_image(fig, "boeing_monthly_line.png", engine="kaleido")
```

<figure><img src="/files/VH0dhnqFlzAY9BM361QX" alt=""><figcaption></figcaption></figure>

### Monthly - Bar chart

Lastly, we change the granularity of the data. Let's create a bar chart of the monthly changes in the Boeing stock price. How does this chart compare to the previous charts? Compare the change the granularity (daily vs monthly) and the different visualization types (line chart vs bar chart).&#x20;

```python
import pandas as pd
import yfinance as yf
import kaleido
import plotly.express as px
import plotly.io as pio

# Download boeing data for 2024 and flatten the index
# interval = '1mo' for monthly data
start = '2024-01-01' #start date for download
end = '2024-12-31' # end date for download
boeing = yf.download('BA', start=start, end=end, interval='1mo') 
boeing.reset_index(inplace=True)
boeing.columns = boeing.columns.to_flat_index()
boeing.columns = ['_'.join(col) for col in boeing.columns]
boeing.columns = ["Date", "Close", "High", "Low", "Open", "Volume"] # rename columns

# Create the visualization with black bars
fig = px.bar(boeing, x="Date", y="Close", color_discrete_sequence=["black"]) 

# Show the image
fig.show()

# Save the image
pio.write_image(fig, "boeing_monthly_bar.png", engine="kaleido")
```

<figure><img src="/files/JMBzNSYTVTYp6E79gzCM" alt=""><figcaption></figcaption></figure>


---

# 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://larhues-personal-organization.gitbook.io/intro-to-data-visualization/exercises-and-examples/stock-market/understanding-boeing-data-over-time.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.
