How to delete from DataTable the rows in a chunk for a certain condition?

I have a DataTable containing data like following: (Assume that each line is each datarow) and each space in each line is the column divider.

PackageA
103 104 141 143
201 203 251 249
311 315 388 390
415 416 417 419
PackageB
103 104 141 143
201 203 251 249
311 315 388 390
PackageC
103 104 141 143
201 203 251 249
311 315 388 390
and so on…

Now there is another Excel file that has the corresponding package codes. It looks like
PackageName | PackageCode
PackageA | SN11414
PackageC | SN13315
PackageD | SN41513

Now comes what I want to do. I need to delete from the datatable, any rows that don’t have the corresponding PackageCode. In the above example, since PackageB doesn’t exist in the Excel file, any rows related to PackageB need to be deleted from the datatable. So the resulting datatable has to look like

PackageA
103 104 141 143
201 203 251 249
311 315 388 390
415 416 417 419
PackageC
103 104 141 143
201 203 251 249
311 315 388 390
and so on…

How could I do this? I read that deleting rows should be done in the reverse order so that deleted rows won’t mess up the later indices, but I can’t go in the reverse order this time because the package name comes at the top of each package section.
Also, we don’t know how many rows there are in each package set.

@tomato25
we had done several projects in which we did such or very similar filterings
The main approach was

  • calculate Indexes of the ranges that are too keep
  • fetch a range with the help of Skip and Take
  • use Tuples to get kept different DataTypes for the Markers

We had done with the use LINQ as we were able to do The steps with less activities. But I reduce for your showcase the complexity in order to get it easier managed and maintained in case of you know less about LINQ. Any remaining LINQ can also be mapped to plain essential UiPath Activities, but then we need a few more steps

Have a look on this prototype doing this filtering with a reduced test data set
tomato25.xaml (14.0 KB)