To visualize our data in the form of Candlesticks, we must be having data that comprises open price, high price, low price, and close price. It is mainly used in financial analysis, so I will use the stock market data of Google of this year starting from January till 8 August.
Japanese commodity Traders created this technique to build this type of chart, and initially, they were known as the Japanese Candlesticks. I will not go in that much detail because our end goal is to visualize this chart using Python.
I will scrape the stock market data of Google from yahoo finance using the pandas_datareader package. If you don’t want to scrape the data and want to use a CSV file, you can also download it from yahoo finance. Now let’s import the necessary packages we need for this task:
import plotly.graph_objects as go
import pandas_datareader as web
Now let’s scrape the data using pandas_datareader:
df = web.DataReader('GOOG', data_source='yahoo', start='2020-01-01', end='2020-08-08')
print(df.head())
High Low … Volume Adj Close
Date …
2019-12-31 1338.000000 1329.084961 … 961800 1337.020020
2020-01-02 1368.140015 1341.550049 … 1406600 1367.369995
2020-01-03 1372.500000 1345.543945 … 1186400 1360.660034
2020-01-06 1396.500000 1350.000000 … 1732300 1394.209961
2020-01-07 1402.989990 1390.380005 … 1502700 1393.339966
#python #data science #machine learning