[Python] Naming dataframe passing it as argument in a function

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I want to know how I can build a function where I can pass the name of the dataframe that I will create as argument.

    Here I have an example:

    list1 = [1,2,3]
    list2 = [4,5,6]

    def say_hi(list1, list2):
    lists = zip(list1, list2)
    df = pd.DataFrame(lists, columns=('A', 'B'))
    return df


    I created a dataframe called df with 3 rows and 2 columns.

    My objective is that:

    def say_hi(list1, list2, DATAFRAME_NAME):
    lists = zip(list1, list2)
    DATAFRAME_NAME = pd.DataFrame(lists, columns=('A', 'B'))
    return DATAFRAME_NAME


    I created a dataframe called DATAFRAME_NAME with 3 rows and 2 columns. Which I gave its name passing an argument.

    Obviously you cannot apply in this way but I want to know how I could do that.

    Continue reading...

Compartilhe esta Página