I have a CSV file which I am parsing using OpenCSV. The CSV file looks like the following:
delta,theta,signal_1,signal_2,signal_3,signal_4,signal_5,signal_6,value_1,value_2,death 71239,56366,8654,21170,16053,27229,5835,8834,3.511244,3.511244,0 234145,160964,16164,20320,29410,17088,9041,8885,5.473104,4.165198,0 76576,23670,11216,22239,8831,15797,13216,7872,2.680331,2.380573,0 44504,39475,12008,18694,14639,25165,11716,24879,2.696564,2.685185,0 275603,31948,10360,7867,15249,16791,8526,4918,2.095088,2.490662,0 80893,16847,7368,19869,5425,11039,6720,5553,3.105438,2.632364,0 70494,323693,61661,3887,17667,35640,16069,8686,18.3219,9.953226,1 808498,57853,13771,15957,13831,20629,15981,11177,4.18285,10.971,1 900628,263343,38948,48837,11122,12378,29276,25673,23.67767,15.39414,1 306369,11836,12448,16708,14225,38644,56110,24842,0.8320562,9.564192,1 2337196,354879,28332,94271,31804,40325,27890,35445,11.15831,11.88935,1 129047,45750,2640,13725,6823,17161,8363,8970,6.705262,6.231878,1 275603,31948,10360,7867,15249,16791,8526,4918,2.095088,2.490662,2 80893,16847,7368,19869,5425,11039,6720,5553,3.105438,2.632364,2 80494,312693,61261,3887,17667,35640,16069,8686,18.3219,9.953226,2 990628,123343,12948,48837,11122,12378,29276,25673,23.67767,15.39414,2 886369,56836,12348,16708,14225,38644,56110,24842,0.8320562,9.564192,2 4437196,234879,34532,94271,31804,40325,27890,35445,11.15831,11.88935,2
Here, the last column is death value and that keep increasing after certain rows (which is totally arbitrary). I would like to find in which row the first death occurred and take the previous 3 rows and write it into a separate csv file. So here, the first death occurs at
70494,323693,61661,3887,17667,35640,16069,8686,18.3219,9.953226,1
So I will consider the preceding three rows:
44504,39475,12008,18694,14639,25165,11716,24879,2.696564,2.685185,0 275603,31948,10360,7867,15249,16791,8526,4918,2.095088,2.490662,0 80893,16847,7368,19869,5425,11039,6720,5553,3.105438,2.632364,0
and write them in to a separate CSV File (suppose this is newCSV.csv). And will do the same with death = 2 and death = 3 and keep appending them in to that newCSV.csv file. I can use the OpenCSV to read them line by line but not getting any idea how to detect the rows based on the death value. Any help would be appreciated.