简体   繁体   English

如何访问在另一个 function (Python) 中返回的 dataframe

[英]How can I access a dataframe that is returned in another function (Python)

How my code works is in two steps.我的代码如何工作分为两个步骤。

I have one file called filter.py which filters my dataframe according to inputs.我有一个名为 filter.py 的文件,它根据输入过滤我的 dataframe。 In this file there is a function update_df() which returns data_filtered在这个文件中有一个 function update_df() 它返回 data_filtered

def update_df(ToEmail, FromEmail, ToJob, FromJob, Date):
    FromEmailF = (data['fromEmail'] == FromEmail)
    ToEmailF = (data['toEmail'] == ToEmail)
    FromJobF = (data['fromJob'] == FromJob)
    ToJobF = (data['toJob'] == ToJob)
    DateF = (data['date'] == Date)
    Filter = (FromEmailF & ToEmailF & FromJobF & ToJobF & DateF)
    data_filtered = data[Filter]
    return data_filtered

In another file, I need to access this data_filtered.在另一个文件中,我需要访问这个 data_filtered。 I first imported update_df but I can't figure out how I can take data_filtered from the function.我首先导入了 update_df,但我不知道如何从 function 中获取 data_filtered。 I tried the following我尝试了以下

def datafilter(data_filtered):
    df = data_filtered
    return df

but now I can't access df either no matter what I do.但现在无论我做什么,我都无法访问 df 。 I just need a way to get the dateframe itself.我只需要一种方法来获取日期框架本身。 I hope any of you guys can help me and I can provide more info if needed.我希望你们中的任何人都可以帮助我,如果需要,我可以提供更多信息。

update_df returns a dataframe, just set a variable to the return of the update_df when you call it update_df 返回一个 dataframe,调用时设置一个变量为 update_df 的返回值

from filter import update_df
df = update_df(ToEmail, FromEmail, ToJob, FromJob, Date)

I would also rename your script filter.py to something else as filter is already a used word in python我还将您的脚本filter.py重命名为其他内容,因为filter已经是 python 中的一个使用词

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

相关问题 如何在python的另一个应用程序中使用函数返回的值? - How can I use a value returned by a function in another application in python? 如何在另一个 python 脚本中访问函数内的变量 - How can I access a variable inside a function in another python script 当 python 没有返回时,如何访问另一个 function 中的值? - How can I access value in another function when there is no return at python? 如何访问 Python 中的 websocket 返回的数据? - How can I access data which is returned by a websocket in Python? 如果我在一个 function 中创建了小部件,我如何使用 PythonE460F8BEA5A9F5118 在另一个 function 中访问它们 - If I created widgets in one function, how can I access them in another function using Python Tkinter? 如何使用Python访问另一台服务器? - How can I access another server with Python? 如何在 python 中有效地组合 function 返回的数据帧? - How can I combine the dataframes returned by a function efficiently in python? 如何在其他函数中使用返回的变量。 Python - How can I use returned variable in other function. Python 如何在python中更改父类函数返回的值 - How can i change the values returned by parent class function in python 如何找出python函数返回的输出数量? - How can I find out the number of outputs returned by a python function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM