0

I have two python files in the same folder: main.py and analysis.py.

In the analysis.py file I have a pandas dataframe called df1, inside a class called Ana(path, file)

I have imported the class to main.py successfully by writing from analysis import Ana, but if I try to do something with df1 it says df1 is not defined.

How do I define df1 in the main.py file? I am quite new to Python so any help will be very appreciated, thank you.

P.S. I forgot to add, I am trying to use the df1 from the Ana function in the analysis.py file in the function Upload in the main.py file

1

2 Answers 2

1

Do a function returning Ana. If it's a member:

def ret_Ana():
    return self.Ana
Sign up to request clarification or add additional context in comments.

Comments

0

Use Ana.df1 instead. It is a class's variable, so you first specify a class instance (or a class itself) and then df1

a = Ana()
a.df1

If you define df1 in the function Upload, you can add df1 to return values like this

def upload(args):
    #your code
    return your_return, df1

So now you can get df1 with return_value, df1 = Ana.upload()

5 Comments

I get AttributeError: 'NoneType' object has no attribute 'df1' when writing that
@andrew_helpme could you please share your Ana code in the question?
@andrew_helpme maybe now I've answered your question?
Sorry I'm not sure what you mean with 'So now you can get df1 with return_value, df1 = Ana.upload()'
@andrew_helpme if upload already returns something and you don't want to lose it, you can return multiple variables read here. if upload does not return anything now, then just write df1 = Ana.upload() and return df1 in upload itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.