簡體   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