[英]How to read Pandas data frame from one file to another file
i have a data from in abc.py i want read the dataframe(DB) in another file xyz.py and perform some other operation我有来自 abc.py 的数据我想读取另一个文件 xyz.py 中的数据帧(DB)并执行一些其他操作
in xyz.py在 xyz.py 中
import abc as abc print(abc.DB) its giving empty data frame.将 abc 导入为 abc print(abc.DB)它给出空数据框。
Need a solution how to access a DataFrame in multiple files.需要一个如何在多个文件中访问 DataFrame 的解决方案。
You can make it work by having the following: abc.py
:您可以通过以下方式使其工作:
abc.py
:
import pandas as pd
df = pd.DataFrame([[0, 0, 0], [1, 1, 1], [2, 2, 2]], ["one", "two", "three"])
xyz.py
: 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:正如预期的那样,我从运行
xyz.py
是这样的:
0 1 2
one 0 0 0
two 1 1 1
three 2 3 4
This should work for you.这应该适合你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.