I have a dataframe defined earlier by this format
vars()['df_zscore_out1']=
I'm trying to access this dataframe inside a function and call this func()
def func():
print(vars()['df_zscore_out1'])
func()
But got
KeyError: 'df_zscore_out1'
I tried passing it in the argument and it works
def func(df):
print(df)
func(vars()['df_zscore_out1'])
Can anyone help to explain this? Thanks!
vars()acts likelocals()."vars()['df_zscore_out1']=" don't do this. Just stop dynamically creating variables. The problem is that in the global scope,vars()returnsglobals(), and in a local scope, it returnslocals(). But you shouldn't be using any of these things, it's a bad design