my goal is to update my 'df1'
dataframe with the new 'df2'
values that are produced by a function. This is the simplification of a more complex script and I cannot exempt myself from using two functions.
import pandas as pd
def new_df2(i):
d2 = {'col1': [i, i-1], 'col2': [i+1, i+2]}
df2 = pd.DataFrame(data=d2)
merge_df(df1, df2)
def merge_df(df1, df2):
df1 = df1.append(df2)
d1 = {'col1': [5, 6], 'col2': [7, 8]}
df1 = pd.DataFrame(data=d1)
for i in range(1,3,1):
new_df2(i)
my result:
print(df1)
col1 col2
0 5 7
1 6 8
expected result:
print(df1)
col1 col2
0 5 7
1 6 8
0 1 2
1 0 3
0 2 3
1 1 4