0

我一直在使用该Series.to_latex()方法在我的 LaTeX 文档中生成一个表格,如下所示:

section.append(NoEscape(s.transform(lambda x: f"{x:,}").to_latex()))

我的系列看起来像这样:

All channels    1099592
Telefe           158738
El Trece         127082
America TV       109763
TN                64598
El Nueve          43450
A24               37639
C5N               36800
ESPN              29356
LN +              27006
Cronica TV        25140
Name: Total:, dtype: int64

但从昨天开始,我的脚本显示以下输出:

FutureWarning: In future versions `DataFrame.to_latex` is expected to utilise the base implementation of `Styler.to_latex` for formatting and rendering. The arguments signature may therefore change. It is recommended instead to use `DataFrame.style.to_latex` which also contains additional functionality.
  section.append(NoEscape(s.transform(lambda x: f"{x:,}").to_latex()))

但是当我尝试实现s.style.to_latex()ors.style.format(thousands = ",").to_latex()语句时,出现以下错误:

AttributeError: 'Series' object has no attribute 'style'

我不确定该样式是否已为 Series 正确实现,因为我在API 参考中没有找到任何 in 指示

我的问题是,是否有办法防止此警告发生,因为它可能会在将来被贬低,并优化我的代码

提前致谢

4

1 回答 1

0

该错误确实表明该属性不适用于系列,而警告显示适用于数据框。我会尝试:

pd.DataFrame(s).style.to_latex()  

或者

pd.DataFrame(s).style.format(thousands = ",").to_latex()
于 2022-01-26T09:41:42.410 回答