Python Forum
Select rows based on a criteria
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select rows based on a criteria
#1
I have a dataset which i need to select specific rows.

1. Select-
   1. If DrAccount or CrAccount contain 9000
        eg-
       -If the line contain DrAccount 1500 & CrAccount as 9000 check whether it has another row with CrAccount 9000 & DrAccount 1500(like a reversal entry).
       -If so select both rows.
       -If there are many rows with CrAccount 9000 & DrAccount 1500, select the similar amount & which is most recent by datetime to the main row considering.
       -If there are no reversal entry ignore main row.

       - Then go to next row, but ignore if the row already selected as reversal entry.
 
  2. If DrAccount or CrAccount not contain 9000
         eg-
       -If the line contain DrAccount 5000 & CrAccount as 2000 check whether it has another row with CrAccount 9000 & DrAccount 1500(like a reversal entry from 9000).
        -If so select both rows.
       -If there are many rows with CrAccount 9000 & DrAccount 1500, select the similar amount & which is most recent by datetime to the main row considering.
       - If there are no reversal entry ignore main row.
       - Then go to next row, but ignore if the row already selected as reversal entry.

Sort - Keep the selected transaction paires as it was selected

Not sure how to create a function to do this. Hope someone can help on this.

My dataset - Attached a CSV file
  DateTime           Amount     Ref         DrCode   CrCode
01-01-17 16:30  1000          Deduct   1500       9000
01-01-17 16:31  2000          Deduct   1400       9000
02-01-17 08:45  1000         Add          9000      1500
02-01-17 08:45  1000        Add           9000     1400
02-01-17 10:40  50000      Add           9000     3000
02-01-17 16:40   4000       Tranfer     1600      2000
02-01-17 16:41   5000       Tranfer     1700     2000
02-01-17 16:42   9000       Deduct     2000    9000
03-01-17 08:45  4000        Add          9000   1600
03-01-17 08:45  5000       Add           9000    1700
03-01-17 10:48  20000    Deduct       4000   9000


Result I'm expecting is a table similar to this
  DateTime             Amount   Ref       DrCode   CrCode
01-01-17 16:30    1000       Deduct  1500      9000
02-01-17 08:45    1000       Add       9000      1500
01-01-17 16:31    2000       Deduct  1400      9000
02-01-17 08:45    1000       Add       9000      1400
02-01-17 16:40    4000      Tranfer   1600      2000
02-01-17 16:41    5000      Tranfer   1700      2000
03-01-17 08:45   4000       Add        9000      1600
03-01-17 08:45   5000       Add        9000      1700






Attached Files

.csv   Dataset1.csv (Size: 442 bytes / Downloads: 69)
Reply


Messages In This Thread
Select rows based on a criteria - by klllmmm - May-04-2017, 02:01 AM
RE: Select rows based on a criteria - by Larz60+ - May-04-2017, 04:04 AM
RE: Select rows based on a criteria - by klllmmm - May-07-2017, 07:58 AM
RE: Select rows based on a criteria - by snippsat - May-07-2017, 01:01 PM
RE: Select rows based on a criteria - by klllmmm - May-08-2017, 07:56 PM
RE: Select rows based on a criteria - by zivoni - May-11-2017, 10:34 AM
RE: Select rows based on a criteria - by klllmmm - May-11-2017, 01:46 PM
RE: Select rows based on a criteria - by zivoni - May-11-2017, 06:10 PM
RE: Select rows based on a criteria - by klllmmm - May-11-2017, 06:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merging rows and adding columns based on matching index pythonnewbie78 3 830 Dec-24-2023, 11:51 AM
Last Post: Pedroski55
  Pandas Dataframe Filtering based on rows mvdlm 0 1,449 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Extracting rows based on condition on one column Robotguy 2 2,228 Aug-07-2020, 02:27 AM
Last Post: Robotguy
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,237 Aug-03-2020, 02:05 AM
Last Post: scidam
  Counting Criteria in Pandas Question Koenig 1 2,179 Sep-30-2019, 05:16 AM
Last Post: perfringo
  select data based on indice Staph 4 2,555 Jul-15-2019, 02:05 AM
Last Post: scidam
  Removing rows at random based on the value of a specific column Mr_Keystrokes 4 5,649 Aug-24-2018, 11:15 AM
Last Post: Mr_Keystrokes
  Updating df rows based on 2 conditions stretch 1 3,155 May-02-2018, 09:15 AM
Last Post: volcano63
  drop duplicate values based on a criteria klllmmm 1 5,621 Apr-28-2017, 10:17 AM
Last Post: zivoni
  Insert values into a column in the same table based on a criteria klllmmm 3 4,240 Apr-13-2017, 10:10 AM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020