Skip to content
Advertisement

Pandas: how select row based on string in previous row – should be a simple solution

I have a a csv file. How do I print the row that follows a row that has a particular string? I need to print all rows that contain “ixation” in them and then the row that follows this row.

Here is my current code

JavaScript

Here is my current output…

JavaScript

But I want…

JavaScript

How do I only print out the lines 66_1to3.., 100_1to3…) that follow only a row with “ixation” in it? This code will be run over a series of csv files in which the exact lines that I need vary between csv files.

Advertisement

Answer

To answer this description: “I need to print all rows that contain “ixation” in them and then the row that follows this row.“, the solution would be:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement