Skip to content Skip to sidebar Skip to footer

Pandas: How To Return Rows Where A Column Has A Line Breaks/new Line ( \n ) With One Of Several Case-sensitive Words Coming Directly After?

This is a follow up to this stackoverflow questions Pandas: How to return rows where a column has a line breaks/new line ( \n ) in its cell? Which shows how to get a word which fol

Solution 1:

Try the below code:

>>> testdf[testdf['A'].str.contains('\nRESULTS|\nMETHODS|\nBACKGROUND')]
                                                   A
0   generates the final summary. \nRESULTS We eva...
1  the cat and bat \n\n\nRESULTS\n teamed up to f...
4  the cat and bat \n\n\nMETHODS\n teamed up to f...
6   generates the final summary. \nBACKGROUND We ...
>>> 

Post a Comment for "Pandas: How To Return Rows Where A Column Has A Line Breaks/new Line ( \n ) With One Of Several Case-sensitive Words Coming Directly After?"