TransWikia.com

colorear filas basado en una condición

Stack Overflow en español Asked by Alex GZ on January 16, 2021

Estoy implementando la siguiente función para colorear las filas que contengan el valor ‘genes LCBs’ en la columna ‘Genes Into LCBs’ de un dataframe, pero cuando exporto el archivo en csv y lo abro, no obtengo el resultado esperado.
################################################################################################################################################################################################
################################################################################################

df

SEQ_NAME    START   END Genes Into LCBs
NC_017357   971765  973198  
NC_017357   973374  974531  
NC_017357   974800  975557  
NC_017357   975761  976096  
NC_017357   976444  977268  
NC_017357   977410  977604  
NC_017357   977775  979698  genes LCBs
NC_017357   979691  981621  genes LCBs
NC_017357   981751  982736  genes LCBs
NC_017357   982736  984003  genes LCBs
NC_017357   984000  985235  genes LCBs
NC_017357   985320  985616  genes LCBs
NC_017357   985606  985869  
NC_017357   985866  986165  genes LCBs
NC_017357   986165  987105  genes LCBs
NC_017357   987102  987557  genes LCBs
NC_017357   987554  987844  genes LCBs
NC_017357   987845  988402  genes LCBs
NC_017357   988403  990145  genes LCBs
NC_017357   990385  990667  genes LCBs
NC_017357   990660  991750  
NC_017357   992124  992560  genes LCBs
NC_017357   992613  993042  genes LCBs
NC_017357   993352  994480  genes LCBs
NC_017357   994662  994880  genes LCBs
NC_017357   994873  995067  genes LCBs
NC_017357   995141  996988  genes LCBs
NC_017357   997002  998171  genes LCBs
NC_017357   998176  998604  genes LCBs
NC_017357   998621  999406  genes LCBs
NC_017357   999410  1000429 genes LCBs
NC_017357   1000430 1002385 genes LCBs
NC_017357   1002555 1003724 genes LCBs
NC_017357   1003727 1005598 genes LCBs
NC_017357   1006281 1006357 genes LCBs
NC_017357   1006380 1006456 genes LCBs
NC_017357   1006516 1006592 genes LCBs
NC_017357   1006659 1006736 genes LCBs
NC_017357   1006920 1007669 genes LCBs
NC_017357   1007753 1009279 genes LCBs
NC_017357   1009276 1009767 genes LCBs
NC_017357   1009948 1012338 genes LCBs
NC_017357   1012442 1013032 genes LCBs
NC_017357   1013058 1014380 genes LCBs
NC_017357   1014399 1014713 genes LCBs
NC_017357   1014795 1015781 genes LCBs
NC_017357   1015781 1018075 genes LCBs
NC_017357   1018090 1019379 genes LCBs
NC_017357   1019381 1020193 genes LCBs
NC_017357   1020315 1021973 genes LCBs
NC_017357   1022002 1022538 genes LCBs
NC_017357   1022554 1024128 genes LCBs
NC_017357   1024138 1025988 genes LCBs
NC_017357   1026011 1026679 genes LCBs
NC_017357   1026681 1027439 genes LCBs
NC_017357   1027443 1028381 genes LCBs
NC_017357   1028437 1030868 genes LCBs
NC_017357   1030865 1031362 genes LCBs
NC_017357   1031619 1032119 genes LCBs
NC_017357   1032341 1032982 genes LCBs
NC_017357   1033036 1033767 genes LCBs
NC_017357   1033829 1035688 genes LCBs
NC_017357   1035673 1035909 genes LCBs
NC_017357   1035922 1036149 genes LCBs
NC_017357   1036348 1037094 genes LCBs
NC_017357   1037361 1037885 genes LCBs
NC_017357   1038066 1039290 genes LCBs
NC_017357   1039287 1040117 genes LCBs
NC_017357   1040183 1041529 genes LCBs
NC_017357   1041543 1042147 
NC_017357   1042157 1044967 

código

def coloring(x):
    df= x.copy()
    mask= df['Genes Into LCBs']== 'genes LCBs'
    df.loc[mask, :]= 'background-color: yellow'
    df.loc[~mask, :]= 'background-color: ""'
    return df
df.style.apply(coloring, axis=None)
outfile = df.to_csv('Mochi_lcbs.csv', sep=";")

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP