Migrate a CSV into two entities with reference I have a CSV as below:

chapter, headings, sentences
1, heading one, "1,2,3,4,5,6,7"
2, heading two, "1,2,3,4,5"
2, heading three, "6,7,8"


I want to migrate it to Drupal. The heading columns have to be migrated to the taxonomy heading. Once a heading is added, it should loop through the value in sentences and update the sentence entity by adding a reference to it. 

The entity to be updated should be loaded matching the sentence column and chapter column. The sentences entity is already pre-populated with data.

Fields in each entity:

Taxonomy:
heading(string)

Entity(sentences):
sentence_no(int)
heading_reference(entity_reference)
sentence(string)
chapter_no(entity_reference)


I tried this tutorial. While the link is straight forward it doesn't really help my need. 

I am ok if I migrate to D7 or D8. However D8 is preferred.
It's fundamental to how the migration process works that it processes one item being written at a time. In this case, since it's sentence entities that are being updated, it needs a migration that processes one sentence at a time. The layout of your CSV here is not well-suited for that, and to work directly from that CSV would require significant hackery. The best approach would be to either generate your CSV in this format in the first place, or have a preprocessing step to put the data in this form:

chapter,sentence,headings
1,1,heading one
1,2,heading one
1,3,heading one
1,4,heading one
1,5,heading one
1,6,heading one
1,7,heading one
2,1,heading two
2,2,heading two
2,3,heading two
2,4,heading two
2,5,heading two
2,6,heading three
2,7,heading three
2,8,heading three


Then, you'd have a migration with source IDs chapter and sentence, setting the heading for each sentence from the headings column.