使用Python pandas获取数据帧的所有行

2024-06-16 21:33:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我运行了一个python代码,得到了如下数据帧输出:

1    Department of Susta... (2)       Community Services (2)
2    Department of Commu... (2)       Community Services (2)
3    Sustainability Vict... (1)       Community Services (1)
4    Southern Grampians ... (1)       Community Services (1)
5    Productivity Commis... (1)       Community Services (1)
6         Parliament of NSW (1)       Community Services (1)
..                           ...                          ...
30      Noosa Shire Council (2)     Sport and Recreation (2)
31   State Library of Qu... (1)     Sport and Recreation (1)
32   Emergency Services ... (1)     Sport and Recreation (1)
33   Department of Susta... (1)     Sport and Recreation (1)

现在我没有7到29行的b/w。如何获取所有行?


Tags: andof数据代码communityproductivitydepartmentsport
3条回答

这只是显示问题,我更喜欢:

#temporaly display 999 rows
with pd.option_context('display.max_rows', 999):
    print (df)

退出with块时,选项值将自动恢复。

从0.20.2开始,默认情况下pandas只显示数据中的60行。你可以用

pd.set_option('display.max_rows',n)

其中n是要显示的行数。

你可以创建这样一个函数

def print_full(x):
    pd.set_option('display.max_rows', len(x))
    print(x)
    pd.reset_option('display.max_rows')

相关问题 更多 >