I am writing a function to pull data from an excel file
output = pd.Dataframe()
def get_help(sheet,head,file):
tmp_df = pd.read_excel(file,sheet_name='Cover')
tmp_df = tmp_df.dropna(how='all')
tmp_df = tmp_df.dropna(axis=1,how='all')
fnf = tmp_df.iloc[3,0]
currency = tmp_df.iloc[5,0]
q_date = tmp_df.iloc[7,0]
tmp_df = pd.read_excel(file,sheet_name=sheet,header=head)
tmp_df = tmp_df.loc[tmp_df['banana'] != '--- End of Sheet ---']
tmp_df['banana'] = tmp_df['banana'].astype(str).str.replace('hi', '')
tmp_df['FNF'] = fnf
tmp_df['banana'] = tmp_df['FNF'] + ' ' + tmp_df['banana']
global output
output = pd.concat([tmp_df,output])
This code works perfectly until I define it as a function and call the function in a for loop.
I have tried changing dataframe names and using global to define a variable. I am very new to python, does this have something to do with scope and namespaces? Thank you for reading.
To clarify: I am expecting a dataframe as the output, the actual output is a empty dataframe.
If I run the same code that I put inside the function in that order I get the dataframe I was expecting. However, when I use that same code inside the get_help() function the dataframe returns empty.