Returning a dataframe in python function

前端 未结 4 1932
-上瘾入骨i
-上瘾入骨i 2021-02-05 21:03

I am trying to create and return a data frame from a python function

def create_df():
    data = {\'state\': [\'Ohio\',\'Ohio\',\'Ohio\',\'Nevada\',\'Nevada\'],         


        
4条回答
  •  无人及你
    2021-02-05 21:27

    Function explicitly returns two DataFrames:

    import pandas as pd
    import numpy as np
    
    def return_2DF():
    
    date = pd.date_range('today', periods=20)
    DF1 = pd.DataFrame(np.random.rand(20, 2), index=date, columns=list('xyz'))
    
    DF2 = pd.DataFrame(np.random.rand(20, 4), index=date, columns='A B C D'.split())
    
    return DF1, DF2
    

    Calling and returning two data frame

    one, two = return_2DF()
    

提交回复
热议问题