The code below generates the number of each type of analyst recommendation for TSLA.O. e.g. Number of Strong Buys, Number of Buys, etc.
My data frame has identical rows e.g. multiple lines with date: 2020-06-12 until to 2020-06-29 when there was an update in the data.
How can I amend the request so that I can an output for each day? E.g. the index of my data frame will be:
2020-06-12
2020-06-13
2020-06-14
2020-06-15
2020-06-16
etc.
instead of:
2020-06-12
2020-06-12
...
2020-06-12
2020-06-29
#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
from datetime import timedelta, date, datetime
from dateutil.relativedelta import relativedelta
#connects to Bill's Eikon terminal
ek.set_app_key('XXXX')
end_date = datetime.now()
start_date = end_date - relativedelta(months=1)
end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
print("start="+start_date_str + " ,end="+end_date_str)
#return dataframe and errors
df,err= ek.get_data('TSLA.O',
['TR.NumOfStrongBuy.date', #show date
'TR.NumOfStrongBuy',
'TR.NumOfBuy',
'TR.NumOfHold',
'TR.NumOfSell',
'TR.NumOfStrongSell'],
{'SDate':start_date_str, 'EDate':end_date_str}) #set start and end date
#show data
df
Thanks