I tried to modify the dataframe through function by looping through rows and return the modified dataframe. In the below code, I pass a dataframe 'ding' to function 'test' and create a new column 'C' by iterating through every row and return the modified dataframe. I expected the test_ding df to have 3 columns but could see only two columns. Any help is highly appreciated.
P.S. It could have other easier methods to accomplish this small task, but I am looking to iterate over rows and would like to see the modifications done on the dataframe to be reflected outside of the function
s1 = pd.Series([1,3,5,6,8,10,1,1,1,1,1,1])
s2 = pd.Series([4,5,6,8,10,1,7,1,6,5,4,3])
ding=pd.DataFrame({'A':s1,'B':s2})
def test(ding):
for index,row in ding.iterrows():
row['C']=row.A+row.B
return ding
test_ding=test(ding)