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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44919307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:55:48  来源:igfitidea点击:

Fetching all rows of dataframe using Python pandas

pythonpandasdataframe

提问by Arti123

I ran a python code and got dataframe output like:

我运行了一个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)

now i don't have rows b/w 7 to 29. How to fetch all rows?

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

回答by jezrael

It is only display problem, I prefer:

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

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

Option values are restored automatically when you exit the withblock.

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

回答by Ken Wei

As of 0.20.2, pandas displays only 60 rows from your data by default. You can change this with

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

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

where nis the number of rows you want it to display.

n您希望它显示的行数在哪里。

回答by Akshay Kandul

You can create a function like this one

你可以创建一个这样的函数

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