I'm trying to make a data frame object global and i'm running into trouble and I'm not sure why. I have this across 2 files: main.py
and helperFunction.py
it comes down to this format
helperFunction.py
:
import pandas as pd
def createGlobalVars(file_path):
global my_df
my_df = pd.read_csv(file_path)
print(my_df.head()
main.py
import helperFunction
def main():
helperFunction.createGlobalVars('the_file.csv')
print(my_df.head())
if __name__=='__main__':
main()
the helper function print is correctly working:
data
0 'my data'
1 'my data'
2 'my data'
3 'my data'
4 'my data'
but the main print is giving me
my_df is not defined
This violates by what I understand about global variables so I must be missing something.