Apr-18-2018, 06:52 AM
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.
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.
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())