So löschen Sie eine Spalte nach Anwendung der StylerfunktionPython

Python-Programme
Anonymous
 So löschen Sie eine Spalte nach Anwendung der Stylerfunktion

Post by Anonymous »

Wie lösche ich die Spalte nach dem Anwenden von Styler? Hier ist meine Stilfunktion: < /p>

Code: Select all

def highlight_late(x):
c1 = 'background-color: red'
#condition
m = x['price_1'] < x['price_main_x']
m2 = x['price_2'] < x['price_main_x']
m3 = x['price_3'] < x['price_main_x']
#empty DataFrame of styles
df1 = pd.DataFrame('', index=x.index, columns=x.columns)

#set column price_2 by condition
df1.loc[m, 'price_1'] = c1
df1.loc[m2, 'price_2'] = c1
df1.loc[m3, 'price_3'] = c1
df1.loc[m, 'url_x'] = c1
df1.loc[m2, 'url_y'] = c1
df1.loc[m3, 'url'] = c1

return df1
< /code>
Methode unten zurückzusetzen me typeRror: 'styler' Objekt unterstützt keine Element -Löschung < /p>
styles = myDF.style.apply(highlight_late, axis=None)
del styles['price_1']
del styles['price_2']
del styles['price_3']
styles.to_excel('test.xlsx')
< /code>
Ich versuche auch: < /p>
mydf.style.hide_columns(['price_1', 'price_2', 'price_3']).to_excel('test.xlsx')
Es funktioniert nicht, Spalten verstecken sich nicht. /pandas.io.formats.style.styler.hide_columns.html funktioniert nicht < /p>

Code: Select all

df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "b", "c"])
df.style.hide_columns(["a", "b"])
df.to_excel('test2.xlsx')

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post