Python Forum
why is the ticker and date different
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is the ticker and date different
#1
Here is my early attempts in using python. i am getting stock data from yahoo but i can see that the ticker, date column headers are lower than the high low open close.
I am definitely missing something.
what is it?
import pandas as pd
import numpy as np
import datetime
import pandas_datareader as pdr

 
py.init_notebook_mode(connected=True)

# we download the stock prices for each ticker and then we do a mapping between data and name of the ticker
def get(tickers, startdate, enddate):
  def data(ticker):
    return (pdr.get_data_yahoo(ticker, start=startdate, end=enddate))
  datas = map (data, tickers)
  return(pd.concat(datas, keys=tickers, names=['ticker', 'date']))

# Define the stocks to download. We'll download of Apple, Microsoft and the S&P500 index.
tickers = ['AAPL','IBM']

# We would like all available data from 01/01/2000 until 31/12/2018.
start_date = datetime.datetime(2016, 1, 1)
end_date = datetime.datetime(2019, 12, 31)

all_data = get(tickers, start_date, end_date)
[Image: viLy1iJ.png]
Reply
#2
Reset index.
all_data = all_data.reset_index()
Try not to use nested functions,it's makes the code harder to read and debug.
There are use cases for it,but i don't see the need here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  replace nan values by mean group by date.year, date.month wissam1974 5 8,322 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Finding date count from a list of date range in pandas trillerducas72 0 2,720 May-24-2018, 02:30 AM
Last Post: trillerducas72

Forum Jump:

User Panel Messages

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