gpt4 book ai didi

python-3.x - 打印 Pandas 数据框时如何抑制 "dtype"行?

转载 作者:行者123 更新时间:2023-12-05 00:58:55 28 4
gpt4 key购买 nike

我有一个数据框,需要打印一些聚合等的输出。

例如,我的脚本中有一行:

pd.f_type = inventory['fruit'].value_counts()
print(f_type)

它的输出是这样的:

apple         2
watermelon 1
pineapple 1
grapefruit 1
orange 1
Name: fruit, dtype: int64

如何删除带有“名称...”的最后一行?我不需要它。我只需要查看实际输出。我需要用for循环或其他东西打印吗?

最佳答案

如果删除最后一行只是为了输出,你可以这样做:

f_type.to_string()

但是,在大型数据帧上使用 .to_string() 时要小心,因为它会转换和打印整个数据帧,而不仅仅是 pd.options.display 中指定的行数.max_rows.

除此之外,如果您有很多列,则输出会非常困惑。在这种情况下,您可能应该改为执行打印循环。

关于python-3.x - 打印 Pandas 数据框时如何抑制 "dtype"行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55815191/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com