我在 pandas 中创建了一个 DataFrame,我想使用颜色索引(低值红色,高值绿色)为单元格着色。我成功地做到了这一点,但是颜色阻止我格式化单元格。
import pandas as pd
df = pd.DataFrame({'a': [0.5,1.5, 5],
'b': [2, 3.5, 7] })
df = df.style.background_gradient(cmap='RdYlGn')
df
Run Code Online (Sandbox Code Playgroud)
返回
但是,当我尝试使用df.round(2)例如来格式化数字时,会弹出以下错误:
AttributeError: 'Styler' object has no attribute 'round'