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

andrew_helpme
  • 33
  • 1
  • 5
  • Andrew try to use functions to return where lives the dataframe then import the function in second file. https://stackoverflow.com/a/20309470/8807216 – Rodrigo Espinoza Jan 28 '20 at 15:06

2 Answers2

1

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

def ret_Ana():
    return self.Ana
Ivan
  • 1,352
  • 2
  • 13
  • 31
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()