繁体   English   中英

如何将 Pandas 数据帧从一个文件读取到另一个文件

[英]How to read Pandas data frame from one file to another file

我有来自 abc.py 的数据我想读取另一个文件 xyz.py 中的数据帧(DB)并执行一些其他操作

在 xyz.py 中

将 abc 导入为 abc print(abc.DB)它给出空数据框。

需要一个如何在多个文件中访问 DataFrame 的解决方案。

您可以通过以下方式使其工作: 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)

正如预期的那样,我从运行xyz.py是这样的:

       0  1  2
one    0  0  0
two    1  1  1
three  2  3  4

这应该适合你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM