【问题标题】:How to print a Panda DataFrame in Jupyter Notebook where it doesn't print the Index or the Column Name如何在 Jupyter Notebook 中打印不打印索引或列名的 Panda DataFrame
【发布时间】:2020-05-24 13:02:50
【问题描述】:

我知道如何使用 .to_string(index=False) 删除索引。但我无法弄清楚如何删除列名。

matrix = [
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9],
    [1,2,3,4,5,6,7,8,9]
]
def print_sudoku(s):
    df = pd.DataFrame(s)
    dff = df.to_string(index=False)
    print(dff)
print_sudoku(matrix)

结果是这样的。

 0  1  2  3  4  5  6  7  8
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9
 1  2  3  4  5  6  7  8  9

我要删除第一行,也就是列名所在的行。

【问题讨论】:

  • 如果你得到了你需要的东西,请接受正确答案的提醒;)

标签: python pandas list dataframe jupyter-notebook


【解决方案1】:

转成字符串时可以使用header=Falsedf.to_string(index=False, header=False)

参考:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_string.html

【讨论】:

  • 谢谢!我不知道我怎么不知道这件事。我可以在 8 分钟内接受这个答案。
猜你喜欢
  • 2019-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
  • 2019-02-27
  • 1970-01-01
相关资源
最近更新 更多