0

I'm using SHARADAR/DAILY data . the dataset/ data frame looks like this.

enter image description here

i need to write a piece of code that returns the latest marketcap value.

when i write the following code...


    trade_date = "2021-05-16"
    df2 = quandl.get_table('SHARADAR/DAILY', ticker='AAPL', date=trade_date)
    print(df2)

the result is empty an dataframe

Series([], Name: marketcap, dtype: object)

i need to do two things...

  1. i need it to return a single value , not a dataframe, so that i can do arithmetic calculations with it.

  2. I need to create a loop that checks.. if value is empty, try to get marketcap for "trade_date" minus one day which is "2021-05-15", else return marketcap. keep minus-ing one day until we get a non-blank/ non-zero market cap

    Empty DataFrame Columns: [ticker, date, lastupdated, ev, evebit, evebitda, marketcap, pb, pe, ps] Index: []

yjng
  • 1
  • 2

1 Answers1

0

mmmm Use datetime and timedelta

import datetime

date_you_want = datetime.datetime.strptime("2020-05-07", "%Y-%m-%d").date() - datetime.timedelta(days=7)

then you can get the date in the format you want

date_you_want.strftime("%Y-%m-%d")

will give you "2020-04-30"