Course Content
Projeccts
RFM Analysis https://statso.io/rfm-analysis-case-study/ Stock Market Performance Analysis https://statso.io/stock-market-performance-case-study/ B2B Courier Charges Accuracy Analysis https://statso.io/b2b-ecommerce-fraud-case-study/ User Engagement Analysis https://statso.io/bounce-rate-case-study/ Customer Lifetime Value Analysis https://statso.io/customer-lifetime-value-analytics-case-study/ Supply Chain Analysis https://statso.io/supply-chain-analysis-case-study/ Demand & Supply Analysis https://statso.io/demand-and-supply-case-study/ Recession Analysis https://statso.io/recession-case-study/ Store Sales & Profit Analysis https://www.kaggle.com/datasets/vivek468/superstore-dataset-final Exploratory Data Analysis https://statso.io/instagram-reach-analysis-case-study/ Accelerometer Data Analysis https://statso.io/accelerometer-data/ User Funnel Analysis https://statso.io/user-funnels-case-study/ Algorithmic Trading https://thecleverprogrammer.com/2021/12/21/get-stock-price-data-using-python/ A/b Testing https://statso.io/a-b-testing-case-study/ T20 World Cup 2022 Analysis https://statso.io/t20-world-cup-2022-dataset/ Twitter Timeline in the Stock Market Analysis https://statso.io/twitter-stock-market-analysis-case-study/ Instagram Reach Analysis https://statso.io/instagram-reach-analysis-case-study/ Screen Time Analysis https://statso.io/screen-time-analysis-case-study/ Stock Market Analysis https://thecleverprogrammer.com/2021/12/21/get-stock-price-data-using-python/ Smartwatch Data Analysis https://thecleverprogrammer.com/2022/05/31/smartwatch-data-analysis-using-python/ Virat Kohli Performance Analysis https://thecleverprogrammer.com/2022/05/10/virat-kohli-performance-analysis-using-python/ Google Search Analysis https://thecleverprogrammer.com/2021/04/27/google-search-analysis-with-python/ Survey Analysis https://www.kaggle.com/datasets/kulturehire/understanding-career-aspirations-of-genz Social Progress Index Analysis https://thecleverprogrammer.com/2022/12/26/social-progress-index-analysis-using-python/ Career Aspirations Survey Analysis https://www.kaggle.com/datasets/kulturehire/understanding-career-aspirations-of-genz iPhone Sales Analysis https://www.kaggle.com/datasets/komalkhetlani/apple-iphone-data Diamond Price Analysis https://www.kaggle.com/datasets/shivam2503/diamonds Covid-19 Impacts Analysis https://www.kaggle.com/datasets/shashwatwork/impact-of-covid19-pandemic-on-the-global-economy IPL 2022 Analysis https://thecleverprogrammer.com/2022/05/03/ipl-2022-analysis-using-python/ Ukraine Vs Russia: Twitter Sentiment Analysis https://www.kaggle.com/datasets/towhidultonmoy/russia-vs-ukraine-tweets-datasetdaily-updated Waiter Tips Analysis and Prediction https://thecleverprogrammer.com/2022/02/01/waiter-tips-prediction-with-machine-learning/ Flipkart Reviews Sentiment Analysis https://thecleverprogrammer.com/2022/02/15/flipkart-reviews-sentiment-analysis-using-python/ Time Series Analysis https://thecleverprogrammer.com/2022/01/17/time-series-analysis-using-python/ TikTok Reviews Sentiment Analysis https://thecleverprogrammer.com/2022/04/12/tiktok-reviews-sentiment-analysis-using-python/ Tinder Reviews Sentiment Analysis https://thecleverprogrammer.com/2022/05/24/tinder-reviews-sentiment-analysis-using-python/ Uber Trips Analysis https://thecleverprogrammer.com/2021/04/21/uber-trips-analysis-using-python/ WhatsApp Chats Analysis https://thecleverprogrammer.com/2021/04/09/whatsapp-chat-analysis-with-python/ Water Quality Analysis https://thecleverprogrammer.com/2021/08/19/water-quality-analysis/ Squid Game Sentiment Analysis https://thecleverprogrammer.com/2021/11/03/squid-game-sentiment-analysis-using-python/ Twitter Sentiment Analysis https://thecleverprogrammer.com/2021/09/13/twitter-sentiment-analysis-using-python/ Movie Rating Analysis for Beginners https://thecleverprogrammer.com/2021/09/22/movie-rating-analysis-using-python/ Worldwide Billionaires Analysis https://thecleverprogrammer.com/2021/06/24/billionaires-analysis-with-python/ Unemployment Analysis https://thecleverprogrammer.com/2021/07/12/unemployment-analysis-with-python/ WhatsApp Chats Sentiment Analysis https://thecleverprogrammer.com/2021/06/06/whatsapp-chat-sentiment-analysis-using-python/ Covid-19 Vaccine Analysis https://thecleverprogrammer.com/2021/04/13/covid-19-vaccines-analysis-with-python/ Financial Budget Analysis https://thecleverprogrammer.com/2021/04/05/financial-budget-analysis-with-python/ Best Streaming Service Analysis https://thecleverprogrammer.com/2021/01/21/best-streaming-service-analysis-with-python/ Data Science Project on Birth Rate Analysis https://thecleverprogrammer.com/2020/05/08/birth-rate-analysis/ Data Science Project on Time Series https://thecleverprogrammer.com/2020/05/08/data-science-project-on-time-series/ Data Science Project on Area and Population https://thecleverprogrammer.com/2020/05/09/data-science-project-on-area-and-population/ Amazon Product Reviews Sentiment Analysis https://thecleverprogrammer.com/2021/07/20/amazon-product-reviews-sentiment-analysis-with-python/ Hotel Reviews Sentiment Analysis https://thecleverprogrammer.com/2021/07/03/hotel-reviews-sentiment-analysis-with-python/ Google Play Store Sentiment Analysis https://thecleverprogrammer.com/2021/05/31/google-play-store-sentiment-analysis-using-python/ Instagram Reach Analysis https://thecleverprogrammer.com/2022/03/22/instagram-reach-analysis-using-python/ Amazon Alexa Reviews Sentiment Analysis https://thecleverprogrammer.com/2021/06/12/amazon-alexa-reviews-sentiment-analysis-using-python/ Real-time Sentiment Analysis https://thecleverprogrammer.com/2021/03/09/real-time-sentiment-analysis-using-python/ Customer Personality Analysis https://thecleverprogrammer.com/2021/02/08/customer-personality-analysis-with-python/ Netflix Data Analysis https://thecleverprogrammer.com/2021/01/16/netflix-data-analysis-with-python/ Covid-19 Vaccine Sentiment Analysis https://thecleverprogrammer.com/2021/01/11/covid-19-vaccine-sentiment-analysis/ Cohort Analysis https://thecleverprogrammer.com/2021/01/08/cohort-analysis-with-python/
0/12
Python Project for Data Analytics
About Lesson

As machine learning practitioners, we need to collect stock price data for regression analysis and time series analysis. We can easily download it from Yahoo Finance. But imagine if we want to create an application where we can analyze the real-time stock prices, we need to collect the latest dataset instead of using the downloaded dataset. So if you want to learn how to get the stock price data between any time interval by using the Python programming language, this article is for you. In this article, I will take you through how to get stock price data using Python.

Get Stock Price Data using Python

Get Stock Price Data using Python

Yahoo Finance is one of the most popular websites to collect stock price data. You need to visit the website, enter the company’s name or stock symbol, and you can easily download the dataset. But if you want to get the latest dataset every time you are running your code, you need to use the yfinance API. yfinance is an API provided by Yahoo Finance to collect the latest stock price data.

To use this API, you need to install it by using the pip command in your terminal or command prompt as mentioned below:

  • pip install yfinance

I hope you have easily installed this API. Now below is how you can get the latest stock price data using Python:

 
 
 
                  Open        High  ...   Adj Close     Volume
Date                                ...                       
2020-12-28  133.990005  137.339996  ...  135.852509  124486200
2020-12-29  138.050003  138.789993  ...  134.043640  121047300
2020-12-30  135.580002  135.990005  ...  132.900681   96452100
2020-12-31  134.080002  134.740005  ...  131.876999   99116600
2021-01-04  133.520004  133.610001  ...  128.617111  143301900

[5 rows x 6 columns]

The above code will collect the stock price data from today to the last 360 days. In this dataset, Date is not a column, it’s the index of this dataset. To use this data for any data science task, we need to convert this index into a column. Below is how you can do that:

 
 
 
        Date        Open        High  ...       Close   Adj Close     Volume
0 2020-12-28  133.990005  137.339996  ...  136.690002  135.852524  124486200
1 2020-12-29  138.050003  138.789993  ...  134.869995  134.043640  121047300
2 2020-12-30  135.580002  135.990005  ...  133.720001  132.900696   96452100
3 2020-12-31  134.080002  134.740005  ...  132.690002  131.876999   99116600
4 2021-01-04  133.520004  133.610001  ...  129.410004  128.617096  143301900

[5 rows x 7 columns]

So as you can see, the final dataset is just like the dataset that we download from Yahoo Finance. This is how we can get stock price data using Python.

Summary

So this is how you can collect the latest stock price dataset between any time interval, using the Python programming language. If you want to get the latest dataset every time you are running your code, you need to use the yfinance API. yfinance is an API provided by Yahoo Finance to collect the latest stock price data. I hope you liked this article on how to get stock price dataset using Python. Feel free to ask your valuable questions in the comments section below.