I am trying to create a dataframe by using the string that I pass as python function attribute. The string is used to feed parameters to scrape some data into a dataframe. I want to rename the dataframe using the string and also rename one of the column names with the string. I am attaching the code below in case it is not clear what I want.
def stock(tick):
tick=tick.upper()
tick, metadata=ts.get_daily(symbol=tick, outputsize='full')
tick['date']=tick.index
tick.index.name='index'
tick=tick[['date', '4. close']]
tick.columns=['date', 'tick_close']
tick.sort_values('date', inplace=True)
tick.drop_duplicates(subset='date', keep='first', inplace=True)
return tick
GLD=stock('GLD')
In the code above, I want the dataframe to be renamed from tick to GLD and rename the column tick_close to GLD_close. I need to do all this by simply passing "GLD" to the function.