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.
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")
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?
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")
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?
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")
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).
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")