【问题标题】:How to print like jupyter notebook's default cell output如何像 jupyter notebook 的默认单元格输出一样打印
【发布时间】:2016-10-23 04:23:57
【问题描述】:

我在 jupyter notebook 中打印 pandas 数据帧时遇到了问题。如果列名真的很长,它会在不同的行中破坏数据框结构。

我怎样才能像 jupyter notebook 默认那样打印它(如图所示 - 第三个单元格)?据我所知,以带边框的表格样式打印数据框的唯一方法是,您必须将变量名称保留为笔记本单元格的最后一个命令。

这里是代码如果你想检查它,

d = pd.DataFrame({'A1_column':[1, 2, 4], 'B1_column':['a', 'b', 'd'],
                 'A2_column':[1, 2, 4], 'B2_column':['a', 'b', 'd'],
                 'A3_column':[1, 2, 4], 'B3_column':['a', 'b', 'd'],
                 'A4_column':[1, 2, 4], 'B4_column':['a', 'b', 'd'],
                 'A5_column':[1, 2, 4], 'B5_column':['a', 'b', 'd'],
                 'A6_column':[1, 2, 4], 'B6_column':['a', 'b', 'd'],
                 'A7_column':[1, 2, 4], 'B7_column':['a', 'b', 'd']})
print(d)
d

【问题讨论】:

    标签: python pandas dataframe ipython jupyter-notebook


    【解决方案1】:

    您可以使用 IPython 的 display 函数来实现:

    from IPython.display import display
    display(d)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 2016-09-06
      • 1970-01-01
      相关资源
      最近更新 更多