Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将数据从一个函数传递到另一个函数?_Python_Python 3.x_Pandas - Fatal编程技术网

Python 如何将数据从一个函数传递到另一个函数?

Python 如何将数据从一个函数传递到另一个函数?,python,python-3.x,pandas,Python,Python 3.x,Pandas,我想使用getExcel函数读取数据,然后将其传递给stats函数,该函数resturds df.descripe(pandas.descripe)显示加载数据的描述性统计信息(平均值、最大值、最小值等)。我该怎么做 将tkinter作为tk导入 从tkinter导入文件对话框 作为pd进口熊猫 def getExcel(): 全球测向 导入文件路径=filedialog.askopenfilename() data=pd.read\u csv(导入文件路径).iloc[:,1:] df=dat

我想使用getExcel函数读取数据,然后将其传递给stats函数,该函数resturds df.descripe(pandas.descripe)显示加载数据的描述性统计信息(平均值、最大值、最小值等)。我该怎么做

将tkinter作为tk导入
从tkinter导入文件对话框
作为pd进口熊猫
def getExcel():
全球测向
导入文件路径=filedialog.askopenfilename()
data=pd.read\u csv(导入文件路径).iloc[:,1:]
df=data.interpolate(method='linear',axis=0).ffill().bfill()
def统计数据(getExcel):
返回df.descripe()

假定您的意思不是简单地让一个函数调用另一个函数,这是一个显而易见的解决方案。您可以使它们成为同一类的方法,并使第二个类所需的数据成为实例数据的一部分……在这种情况下,它很可能在构造时初始化

import tkinter as tk
from tkinter import filedialog
import pandas as pd

class App:
    def __init__(self):
        df = getExcel()

    def getExcel(self):
        import_file_path = filedialog.askopenfilename()
        data = pd.read_csv (import_file_path).iloc[:,1:]  
        self.df = data.interpolate(method='linear', axis=0).ffill().bfill()
        return self.df 

    def stats(self): 
        return self.df.describe()

getExcel
需要返回数据。然后,您可以将该数据传递到
stats

def getExcel():
    ...
    return df

def stats(df): 
    return df.describe()

df = getExcel()
result = stats(df)

去。。。?请具体说明您试图实现的目标,否则我们将无法帮助您。我希望能够使用getExcel函数读取数据,然后将其传递给stats函数,该函数restrds df.descripe(pandas.descripe)显示加载数据的描述性统计信息(平均值、最大值、最小值等)。