小编Nam*_*shi的帖子

类型错误:(“不支持的操作数类型 -:'decimal.Decimal' 和 'float'”,'发生在索引增长(%)')

这是我的数据框-

    c2_name Q1_GMV      Q2_GMV     growth(%)
0   A       1170727260  221801763   -81
1   B       1604716749  829186592   -48
2   C       661473481   553698141   -16
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用 Pandas 样式将 CSS 添加到数据帧输出中。

# Set colormap equal to seaborns light green color palette
cm = sns.light_palette("green", as_cmap=True)

(df.style
  .background_gradient(cmap=cm, subset=['growth(%)'])
  .set_caption('This is a custom caption.')
  .set_table_styles(styles))
Run Code Online (Sandbox Code Playgroud)

但是得到这个错误

TypeError: ("unsupported operand type(s) for -: 'decimal.Decimal' and 'float'", 'occurred at index growth(%)')
Run Code Online (Sandbox Code Playgroud)

试图让它看起来像这样

这里

styling pandas jupyter-notebook pandas-styles

7
推荐指数
1
解决办法
8669
查看次数

标签 统计

jupyter-notebook ×1

pandas ×1

pandas-styles ×1

styling ×1