2017-04-25 3 views
0

Ich habe einen Datenrahmen mit Tabellenstil, die ich erstellt:Wie setze ich eine Zelle, nicht eine Spalte oder Zeile in einem Datafram mit Farbe?

tableyy = final.style.set_table_attributes('border="" class = "dataframe table table-hover table-bordered"').set_precision(10).render() 

ich gehe durch diesen Coloring Cells in Pandas, Conditionally change background color of specific cells, Conditionally format Python pandas cell und Colour cells in pandas dataframe, ich in der Lage noch nicht eine Zelle mit Farbe setzen nicht dem gesamten Datenrahmen ohne irgendeine Bedingung. Jeder hat irgendwelche Ideen, ich probiere diesen Farbcode schon seit einem Monat aus, also kann Hoffnung von jedem von euch beraten werden, danke.

Antwort

0

Versuchen Sie folgendes:

data = pd.DataFrame(np.random.randn(6, 6), columns=list('ABCDEF')) 

def highlight_cells(x): 
    df = x.copy() 
    #set default color 
    #df.loc[:,:] = 'background-color: papayawhip' 
    df.loc[:,:] = '' 
    #set particular cell colors 
    df.iloc[0,0] = 'background-color: red' 
    df.iloc[1,1] = 'background-color: orange' 
    df.iloc[2,2] = 'background-color: yellow' 
    df.iloc[3,3] = 'background-color: lightgreen' 
    df.iloc[4,4] = 'background-color: cyan' 
    df.iloc[5,5] = 'background-color: violet' 
    return df 

t = data.style.apply(highlight_cells, axis=None) 
t 

enter image description here

Verwandte Themen