max494
max494

Reputation: 13

How to call a DataFrame that is build in another module/method?

probably a simple question but I can't find any solution.

I do have a file called irc_daten.py, where I built a class, called IrcData, that contains various methods. This methods collect several data in DataFrames that will be used in many files by importing the methods. But somehow I can't call this DataFrames.

This is irc_daten.py:

class IrcDaten():
    
    def __init__(self):
        pass
        
    def stammdaten():
        global stammdaten
        stammdaten = pd.read_excel(path_stammdaten)

But using this DataFrame in another file doesn't seem to work:

from irc_daten import IrcDaten
IrcDaten.stammdaten()

print(stammdaten)

NameError: name 'stammdaten' is not defined

Any ideas? Thanks in advance.

Upvotes: 1

Views: 235

Answers (2)

user14923778
user14923778

Reputation:

Try importing in this way:

from irc_daten import IrcDaten as ID
y=ID.stammdaten()

print(y)

Upvotes: 0

John Stud
John Stud

Reputation: 1779

try this instead:

class IrcDaten():
    
    def __init__(self):
        pass
        
    def stammdaten():
        stammdaten = pd.read_excel(path_stammdaten)
        return stammdaten

from irc_daten import IrcDaten
df = IrcDaten.stammdaten()

Upvotes: 1

Related Questions