SoFunction
Updated on 2024-11-16

python extracts a whole row of data containing a keyword.

Problem Description:

As shown in the figure below, there is a data table with nearly 2,000 rows, and you need to extract all the rows containing the keyword 'Cervical Contouring, Central Group (Group VI)', and the extracted table should not change the original order.

python提取包含关键字的整行数据

Problem Analysis:

At first, I wanted to use excel's screening function, but found that only a single column screening, due to the keywords in the P, S, V, Y, AB columns have, so you need to screen 5 times. But after screening and then integrated together with the table order is messed up, and the original table sorting law is not known, can not be realized through a simple sorting. So decided to use Python to write a code to solve this problem ~

python提取包含关键字的整行数据

The table generated by python looks like this ^_^ Those blank rows are the ones that don't meet the requirements, we still need to remove those blank rows~

python提取包含关键字的整行数据

The method is very simple, use excel's positioning conditions - & gt; null value - & gt; the selected rows will be deleted:

python提取包含关键字的整行数据

python提取包含关键字的整行数据

python提取包含关键字的整行数据

Above this python extract the whole line of data containing keywords method is all that I have shared with you, I hope to give you a reference, and I hope you support me more.