Python Forum

Full Version: Code should download and output trading data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Python gurus.

I am trying to create and run a Python script that will download and output the AAPL stock data into an Excel file from the NASDAQ site < https://www.nasdaq.com/market-activity/s...historical >. The data file should contain the following data sets – Date, Close, Open, High and Low in individual columns and it should be limited to all days of the year 2020. Finally, the code should read the data into Pandas format ready for analysis.

Here is what I have so far...
import pandas as pd
from pandas_datareader import data, wb  
import datetime

start = datetime.datetime(2020,1,1)
end = datetime.date(2020,12,31)
 
apple = data.DataReader("AAPL", "yahoo", start, end)
 
type(apple)

apple.head()
When the code is run in Jupyter Notebook, I get "some" output (data for 5 days), but not for all days and certainly not in an Excel file. Moreover, the data is being downloaded from Yahoo!
Output:
Date High Low Open Close Volume Adj Close 2020-01-02 75.150002 73.797501 74.059998 75.087502 135480400.0 74.333511 2020-01-03 75.144997 74.125000 74.287498 74.357498 146322800.0 73.610840 2020-01-06 74.989998 73.187500 73.447502 74.949997 118387200.0 74.197395 2020-01-07 75.224998 74.370003 74.959999 74.597504 108872000.0 73.848442 2020-01-08 76.110001 74.290001 74.290001 75.797501 132079200.0 75.036385
Any guidance here would be deeply appreciated.

Thank you.
with DataFrame.head() you display/print just the head of the dataframe - header and 5 rows, just to peek at the data so to say. Here are the docs: https://pandas.pydata.org/pandas-docs/st....head.html
if you want to save the dataframe to excel file you can use DataFrame.to_excel() method
(Mar-02-2021, 07:14 AM)buran Wrote: [ -> ]with DataFrame.head() you display/print just the head of the dataframe - header and 5 rows, just to peek at the data so to say. Here are the docs: https://pandas.pydata.org/pandas-docs/st....head.html
if you want to save the dataframe to excel file you can use DataFrame.to_excel() method

Thanks Buran!