Reputation: 117
i have a data from in abc.py i want read the dataframe(DB) in another file xyz.py and perform some other operation
in xyz.py
import abc as abc print(abc.DB) its giving empty data frame.
Need a solution how to access a DataFrame in multiple files.
Upvotes: 1
Views: 1126
Reputation: 233
You can make it work by having the following:
abc.py
:
import pandas as pd
df = pd.DataFrame([[0, 0, 0], [1, 1, 1], [2, 2, 2]], ["one", "two", "three"])
xyz.py
:
# you could also write "from test import df"
from test import *
print(df)
The output I get from running xyz.py
is this, just as expected:
0 1 2
one 0 0 0
two 1 1 1
three 2 3 4
This should work for you.
Upvotes: 2