![]() |
How to loop through Rows - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to loop through Rows (/thread-10922.html) |
How to loop through Rows - SriRajesh - Jun-15-2018 Hi, [python]I have belwo DataFrame: Input1: first_name pre_score mid_score post_score UAT_F3 4 25 5 UAT_F5 24 94 43 UAT_F2 31 57 23 UAT_F6 2 62 23 UAT_F8 3 70 51 Input2: first_name pre_score mid_score post_score UAT_F3 4 25 5 UAT_F5 24 94 43 UAT_F2 31 57 23 UAT_F6 2 62 23 UAT_F8 3 70 51 I want to loop through the rows of the input1&Input2 data and on each iteration, copy the current rows from Input2(first_name store &pre_score) and previous row =(i-1th row) from Input1, and do something.I use the below code, but I could not be able to access & store. [python] newData=[] for index, row in Input1.iterrows(): print(index) tempData1=Input1.loc[[index-1,:]] tempData2=Input2.loc[[index,:]] temp=[tempData1,tempData2] newData.append(temp) Desired Output: first_name pre_score mid_score post_score UAT_F5 4 25 5 UAT_F2 24 94 43 UAT_F6 31 57 23 UAT_F8 2 62 23 Kindly someone help, and many thanks in advance,[/python] |