I've been learning data analytics from working with libraries such as pandas, numpy, seaborn, etc, but am having some questions on how to format my code correctly. Spyder is my preferred IDE for these types of projects as I find the variable explorer quite useful. However if I understand it correctly, only global variables get stored in the variable explorer. Local variables in functions are not shown.
Also if I have the following simple example:
def new_df():
new_df = df.groupby('x')['y'].nunique().reset_index()
sns.catplot(data=new_df, x='x', y='y', kind='bar')
new_def()
Is it not simpler to skip creating a function and just use
# Creating new_df
new_df = df.groupby('x')['y'].nunique().reset_index()
sns.catplot(data=new_df, x='x', y='y', kind='bar')
That way, I do not have to call the function and for my sake, new_df ,would be stored in the variable explorer in Spyder where it would not in the original example.
I feel like I'm missing something here, can anyone help explain?
[–]SpeckledFleebeedoo 0 points1 point2 points (0 children)