I am trying to understand how to run a function that must take a data frame, append some rows and return the updated df. I tried to make a copy of the original data frame, make the append operation and then return a new df as a result of the function. However, this method does not work.
import pandas as pd
df1 = df = pd.DataFrame({"a":[1, 2, 3, 4],
"b":[5, 6, 7, 8]})
def append_function(d1):
d2=d1.copy(deep=True)
display(d2)
df2 = pd.DataFrame({"a":[12, 22, 33],
"b":[51, 62, 73]})
d2.append(df2)
display(d2)
return d2
df3=append_function(df1)
display(df3)
The answer is always the content of the original data frame.
Can someone please give me an explanation about that?