Python Forum
Code should download and output trading data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code should download and output trading data
#1
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.
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 357 Feb-28-2024, 07:15 PM
Last Post: deanhystad
Star Pairs Trading Simulation Kiitoos 0 234 Feb-19-2024, 08:27 PM
Last Post: Kiitoos
  Failed to download Qualtrics data using API balaKrishnaV 4 3,886 Sep-16-2023, 03:12 PM
Last Post: Jfreeland
  I cannot able to see output of this code ted 1 751 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  why I dont get any output from this code William369 2 1,123 Jun-23-2022, 09:18 PM
Last Post: William369
  Yfinance - Intraday stock data with yf.download diogo_80 2 5,960 Apr-29-2022, 05:07 AM
Last Post: processingclouds
  How can I organize my code according to output that I want ilknurg 1 1,164 Mar-11-2022, 09:24 AM
Last Post: perfringo
  how to manage crypto trading flooding data from exchange servers Mikeardy 0 1,232 Dec-26-2021, 08:31 PM
Last Post: Mikeardy
  cbot ctrader automate trading hl29951 1 1,646 Jul-25-2021, 08:14 PM
Last Post: Larz60+
  download with internet download manager coral_raha 0 2,940 Jul-18-2021, 03:11 PM
Last Post: coral_raha

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020