Python Forum
Passing data between functions, got it working, but need clarification please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing data between functions, got it working, but need clarification please
#1
I made a basic script that passes a dataframe between 2 functions.

I understand how it works, except for the meaning of the last line.

test2(test1())
Does this mean that all the code from test1 is merged within test2?

I get that it's calling both functions, but I don't fully understand why test1 has to be inside test2, and what exactly is happening at run time.

import pandas as pd


'''
test1 function creates the dataframe
'''


def test1():
    list1 = ["item1", "item2", "item3", "item4", "item5", "item6",
             "item7", "item8", "item9", "item10", "item11", "item12"]

    df = pd.DataFrame(list1, columns=['Col 0:'])  # create new dataframe from list1
    df.insert(1, 'Col 1:', "")  # insert new column
    df.insert(2, 'Col 2:', "")  # insert new column

    return df  # pass the dataframe outside the function


'''
test2 function calls the dataframe from test1() makes a change to the cell data and prints df 
'''


def test2(df):  # call df which was passed from test1()

    df.iloc[5, 2] = "NEW CELL DATA"

    print(df)


test2(test1())
Reply


Messages In This Thread
Passing data between functions, got it working, but need clarification please - by digitalmatic7 - Apr-18-2018, 06:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Having trouble setting the X-Ticks for a data set I am working with. Mr_OHagan 1 531 Jan-22-2024, 09:12 PM
Last Post: deanhystad
  I'm working onn below code to extract data from excel using python kiran 1 3,306 Oct-24-2017, 01:42 PM
Last Post: kiran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020