Override global variable inside function not working with Spyder 4

I try to override globally defined Dataframes from within a function.
Somehow the global values do not change, printing the dataframes within the functions works with the expected values.

import pandas as pd

rawData = pd.read_csv("music.csv")
appTitles =pd.DataFrame #also with pd.DataFrame() wont get affected

def loadTitles(df=rawData):
    global appTitles
    appTitles = pd.DataFrame({'Title' : df['title']})
    print(appTitles) 
return appTitles #(second 'print' to screen)

#RUN FILE
#CALL FUNCTION: loadTitles() #-> No Variable appTitles

The appTitles variable in the variable explorer remains empty or nonexistent (depending use of pd.DataFrame/pd.DataFrame()) Thank you!

EDIT: After @4turkuaz commented that on his environment everthing works as expected, I tried Python console within Windows cmd and also on Spyder3 with Python 3.7.4 & IPython 7.8.0 where also everything worked fine.

Only on Spyder4 with Python 3.7.5 & IPython 7.10.1 it won’t work. Maybe a bug? I don’t know…

EDIT: Downgrading Spyder4 to Python 3.7.4 & IPython 7.8.0 did not solve the problem. I’m assuming that something within Spyder4 or the Anaconca Environment even though I installed it over and over is not correct.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

(Spyder maintainer here) You need to go to the menu

Run > Configuration per file

and activate the option called Run in console's namespace instead of an empty one, for you to be able to modify global variables in your code.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x