Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
55 views
in Technique[技术] by (71.8m points)

python - 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.

question from:https://stackoverflow.com/questions/65940836/how-to-call-a-dataframe-that-is-build-in-another-module-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...