简体   繁体   English

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

[英]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.

相关问题 如何将 JSON 数据的多个列表从一个文件读取到 Pandas - How to read multiple lists of JSON data from one file into Pandas 如何使用pandas read_pickle从qrc资源文件中读取包含pandas数据框的pickle文件? - How can I read pickle file containing pandas data frame from qrc resource file with pandas read_pickle? 如何在Pandas中读取带有行名称的数据框的CSV文件 - How to read CSV file with of data frame with row names in Pandas 使用json将文件读入pandas数据框 - Use json to read the file into a pandas data frame 如何从另一个pandas数据框中减去一行? - How to subtract rows of one pandas data frame from another? 如何使用 pandas 从 .log 文件中读取数据 - How to read data from .log file with pandas pandas:从一个数据帧添加行到另一个数据帧? - pandas: Add row from one data frame to another data frame? 将数据框从一个Jupyter Notebook文件导入另一个 - Import data frame from one Jupyter Notebook file to another 根据 pandas 中另一个数据帧中的某些条件将值从一个数据帧拆分到另一个数据帧 - Splitting values from one data frame to another data frame based on certain conditions in another data frame in pandas Python Pandas:将数据从一个数据帧归一化到另一个数据帧 - Python Pandas: Denormalize data from one data frame into another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM