如何在print(df.tostring())之后用Python打印粗体

问题描述 投票:0回答:1

非常令人沮丧,我想在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))
python jupyter-notebook printf tostring
1个回答
0
投票

似乎您正在将整个数据帧df覆盖为df.style。您可能要尝试:

df1.style = df1.style.apply(highlight_max)
© www.soinside.com 2019 - 2024. All rights reserved.