从具有数据帧格式的函数返回两个数据帧 [英] Return two data frames from a function with data frame format

查看:89
本文介绍了从具有数据帧格式的函数返回两个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个函数返回两个数据帧,像这样:

I want to return two data frames from a function, like this:

def test():
    df1 = pd.DataFrame([1,2,3], ['a','b','c'])
    df2 = pd.DataFrame([4,5,6], ['d','e','f'])
    return df1
    return df2
test()

但是该函数仅返回一个数据帧df1.如何以漂亮的数据帧格式(而不是cmd黑色背景格式)返回两者?

But the function only returns one data frame df1. How to return both in pretty data frame format, not in cmd black background format?

当我尝试同时使用两者返回时

When I tried to return both using

return df1, df2

在Jupyter Notebook中,输出以类似于黑色背景cmd的格式返回数据帧,而不是以正确的数据帧格式.

in the Jupyter Notebook, the output returns the data frames in a black background cmd-like format, and not in proper data frame format.

推荐答案

如何解决:

def test():
    df1 = pd.DataFrame([1,2,3], ['a','b','c'])
    df2 = pd.DataFrame([4,5,6], ['d','e','f'])
    return df1, df2

a, b = test()
display(a, b)

打印输出:

    0
a   1
b   2
c   3

    0
d   4
e   5
f   6

这篇关于从具有数据帧格式的函数返回两个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆