【发布时间】:2019-05-08 14:28:26
【问题描述】:
在这被标记为重复之前,我已经尝试了以下主题的代码,但到目前为止没有一个对我有用:
[Colouring one column of pandas dataframe]
[Format the color of a cell in a panda dataframe according to multiple conditions]
[how to color selected columns in python dataframe?]
我的代码可以生成三个看起来像这样的 pandas 数据框:
RowName Orders Market StartTime StopTime
Status
good A 9 gold 10:00:00 10:09:45
.
.
.
bad B 60 silver 07:54:43 08:02:12
RowName Orders Market StartTime StopTime
Status
good E 19 plat. 10:00:00 10:09:45
.
.
bad F 54 mercury 07:54:43 08:02:12
RowName Orders Market StartTime StopTime
Status
great D 3 alum. 10:00:00 10:09:45
.
.
ok C 70 bronze 07:54:43 08:02:12
Status 列设置为每一帧的索引
对于每一帧,我想用值#D42A2A(又名红色)突出显示StartTime 列,而不管给定单元格中的值是什么。
如何做到这一点?
最近失败的尝试:
def column_style(col): if col.Name == 'StartTime': return pd.Series('bgcolor: #d42a2a', col.index)def col_color(data): color = 'red' if data != '' else 'black' return 'color: %s' %color frame.style.applymap(col_color, subset=['StartTime'])
但这也失败了。
注意:
我在 linux shell 中使用 VI
整个脚本被 IE(Internet Explorer)调用,所以脚本的输出是 html
我正在使用 BS (beautifulsoup) 从几个站点抓取数据并将结果汇总到一个页面上 {*在抓取初始网站并创建所需网站(称为 Page1)后,我尝试在同一脚本中抓取 Page1 并通过
.attrs方法添加 html 行,但这“失败”,即网络服务器时间跑步时外出}
【问题讨论】: