相关疑难解决方法(0)

python xlwt设置单元格的自定义背景颜色

我使用python 2.7和xlwt模块进行excel导出

我想设置我知道可以使用的单元格的背景颜色

style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')
Run Code Online (Sandbox Code Playgroud)

但我想设置自定义颜色smth.比如#8a8eef或者是否有可能颜色的调色板,因为浅蓝色不起作用:)

谢谢

python format excel xlwt

23
推荐指数
3
解决办法
4万
查看次数

How to save pandas to excel with different colors

I have a dataframe

df = pd.DataFrame(columns = ['id', 'name', 'age'])
df.loc[len(df), :] = [1, 'John', 21]
df.loc[len(df), :] = [2, 'Mary', 19]
df.loc[len(df), :] = [3, 'Ann', 27]
df.loc[len(df), :] = [4, 'Ben', 18]
Run Code Online (Sandbox Code Playgroud)

I want to save it to excel file using xlsxwriter.

However, I want the age larger than 20 to be in red.

In other words, 21 and 27 should appear red in the excel file.

How to do it?

python dataframe

5
推荐指数
1
解决办法
7367
查看次数

为 Pandas Dataframe.to_html() 的单列着色

在将其标记为重复之前,我已经尝试了以下主题中的代码,但到目前为止没有一个对我有用:

[为 pandas 数据框的一列着色]

[根据多种条件格式化 panda 数据框中单元格的颜色]

[如何在 python 数据框中为选定的列着色?]

我有代码可以生成三个 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 …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

3
推荐指数
1
解决办法
5850
查看次数

标签 统计

python ×3

dataframe ×2

excel ×1

format ×1

pandas ×1

xlwt ×1