Return two data frames from a function with data frame format

≯℡__Kan透↙ 提交于 2019-12-30 19:51:28

问题


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()

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

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


回答1:


How about this:

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)

This prints out:

    0
a   1
b   2
c   3

    0
d   4
e   5
f   6


来源:https://stackoverflow.com/questions/52568474/return-two-data-frames-from-a-function-with-data-frame-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!