# How to correctly append a Dataframe?

• Python
I have code snippet as below and when i run it, the dataframe seems to append after every loop and does not add the previous row into the frame, so at each time only one row is populated into the new dataframe. How do I ensure that the append function adds the previous row as well?

Python:
    df2=pd.DataFrame()

for i,row in df.iterrows():
c =check_function(row)

if check_function != 'No':
calc_function= calc_function_1(row, c)
df3 = df2.append(calc_function_1)
print df3

phinds
Gold Member
I'm not familiar w/ the dataframe object, but it looks to me like

calc_function= calc_function_1(row, c)
df3 = df2.append(calc_function_1)

is defining "calc_function" to be a row out of calc_function_1 that you want to append to df2 but instead of appending it, you then append the entire calc_function_1

anorlunda
Staff Emeritus
df3 = df2.append(calc_function_1)
print df3

df2 = df2.append(calc_function_1)
print df2

yes, i found the solution. It was the way i was appending the location of the .append which was not correct.

anorlunda
Staff Emeritus
yes, i found the solution. It was the way i was appending the location of the .append which was not correct.

Please remember that it's just ordinary politeness when you find your own answer, to post it on the thread so that others stop trying to help.

sure. i was going to update the thread as i just found the solution. thanks.