'How to segregate dataframe along with highlight column

import pandas as pd
test_df =pd.DataFrame({"col1":[1,12,3,4],
            "col2":[3,14,5,6],
             "col3":[4,5,6,7]})

print(test_df)
   col1  col2  col3
0     1     3     4
1    12    14     5
2     3     5     6
3     4     6     7

def highlight(row):
    ret =["" for _ in row.index]   
    if row['col3'] == 5:                                                                         
        ret[row.index.get_loc('col3')] ="background-color: #f2f20a"
    if row['col2'] == 5:                                                                         
        ret[row.index.get_loc('col2')] ="background-color: #f2f20a"
        
    return ret
dd= test_df.style.apply(highlight, axis=1)
print(dd)
    col1 col2   col3
0   1    3      4
1   12  14      **5**
2   3   **5**   6
3   4   6       7

How can I separate create dataframe or excel which has only a highlight row only? In this case, only rows 1, 2 will be come in separate excel or dataframes.

Thanks in Advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source