非常令人沮丧,我想在df.to_string()之后对我的df中的最后一列应用粗体不幸的是,我无法执行此操作,因为出现此错误:“ Styler”对象没有属性“ to_string”
任何想法?
def highlight_max(x):
return ['font-weight: bold' if v == x.loc['Column_Total'] else ''
for v in x]
dfs.style.apply(highlight_max)
decimals = 1
df1['Daily'] = df1['Daily'].apply(lambda x: round(x, decimals))
df1['Daily'] = df1['Daily'].apply(lambda x: "£{0:,.0f}".format((x)))
df1['Trade Date'] = pd.to_datetime(df1['Trade Date'])
df1['Trade Date'] = df1['Trade Date'].dt.strftime('%m/%d/%Y')
df1 = df1.style.apply(highlight_max)
print(df1.to_string(columns=['Port','Date','Daily'], index=False))
似乎您正在将整个数据帧df
覆盖为df.style
。您可能要尝试:
df1.style = df1.style.apply(highlight_max)