简体   繁体   English

如何在 python 中有效地组合 function 返回的数据帧?

[英]How can I combine the dataframes returned by a function efficiently in python?

I have a function which returns many values on every run but I am interested in dataframe being returned.我有一个 function 每次运行都会返回许多值,但我对返回的 dataframe 很感兴趣。 I am currently using a list to store dataframes and then at the end I use pd.concat to convert all the dfs in to a single df.我目前正在使用一个列表来存储数据帧,然后最后我使用 pd.concat 将所有 dfs 转换为单个 df。 It's working fine but when I try to push this code for review I face linting errors "too many local variables'. There's no way I can deal with other varibales so, is there a way more efficient to store these dataframes and then later convert it to a single frame.它工作正常,但是当我尝试推送此代码进行审查时,我遇到了“太多局部变量”的 linting 错误。我无法处理其他变量,所以有没有一种更有效的方法来存储这些数据帧,然后再转换它到单个帧。

Currently, the code is something like this:目前,代码是这样的:

df_list = []

....

_, _, df = function_call()

df_list.append(df)

....

df = pd.concat(df_list, axis=0)

Would it be possible to store the argument values to pass to the dataframe generating function in a list, and then use a generator expression in the pd.concat call?是否可以在列表中存储要传递给 dataframe 生成 function 的参数值,然后在pd.concat调用中使用生成器表达式?

Something like this:像这样的东西:

kwargs_list = []

kwargs = {'arg1': val1, 'arg2': val2}
kwargs_list.append(kwargs)
...

df = pd.concat(function_call(**kwargs) for kwargs in kwargs_list)

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

相关问题 合并从python多进程调用函数返回的数据帧 - Combine dataframes returned from python multiprocess calling function 如何获取从 class function 返回的多个数据帧? - How can I get multiple dataframes returned from a class function? 如何有效地执行 Python 中两个 pandas 数据帧的笛卡尔积? - How can I efficiently perform the cartesian product of two pandas dataframes in Python? 如何在与 python 的循环中有效地调用 function? - How can I efficiently call a function in a loop with python? Python - 如何在 3 列上组合两个数据框并保留两个数据框中的列? - Python - How can I combine two data frames on 3 columns and keep columns from both dataframes? 如何有效地将Pandas中的类似数据帧组合成一个巨大的数据帧 - How do I efficiently combine similar dataframes in Pandas into one giant dataframe 如何在 python 中组合多个数据帧 - How to combine multiple dataframes in python 如何根据 Pandas 中的一列列表组合两个数据帧 - How can I combine two dataframes based on a column of lists in Pandas 组合从 TDA-API python 库返回的多个数据帧 - Combine multiple dataframes returned from TDA-API python library 如何在python中有效地合并两个具有容差的数据帧 - How to merge efficiently two dataframes with a tolerance in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM