【问题标题】:I want to enter title at the top the table and some data at bottom using python我想使用python在表格顶部输入标题并在底部输入一些数据
【发布时间】:2021-04-27 08:06:35
【问题描述】:

我使用 python 的 pandas 库打印了一个 csv 格式的表格,但我想在打印之前在表格底部添加标题和一些数据。

这是我用于打印表格的 python 代码

我希望我的表格这样打印,标题为:表格 5:瑙鲁加权点系统,底部:状态 = 0 A = 8/获胜者 B = 5.82 C = 6.65

【问题讨论】:

  • 你不能在head()之前和之后使用print()吗?最终你将不得不重写函数head() 中的所有代码。或者它可能会更改to_html()中的模板

标签: python pandas numpy matplotlib jupyter


【解决方案1】:

这个例子可能会引导你走向正确的方向..

import matplotlib.pyplot as plt
import pandas as pd

my_frame = pd.DataFrame(data={'Voters':['V1','V2','V3','V4'],
                              'True Preferece':['B>A>C','C>B>A','A>C>B','B>A>C'],
                              'Declared preference':['A>B>C','B>C>A','C>A>B','A>B>C'],
                              'Weights':[3,2,4,2]})
#my_frame Display pandas table

fig = plt.figure(figsize = (8, 2))
ax = fig.add_subplot(111)

ax.table(cellText = my_frame.values,
          rowLabels = my_frame.index,
          colLabels = my_frame.columns,
          loc = "center"
         )
ax.set_title("Table 5: Nauru Weigted Point system")

ax.axis("off");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2018-02-05
    • 2020-07-30
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多