列表元素与数据框描述何时发生? [英] Listing elements vs dataframe description When happens when?

查看:74
本文介绍了列表元素与数据框描述何时发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能非常简单,但我不知道出了什么问题. 我在列出DataFrame的元素时遇到麻烦.有时列出了DataFrame的元素,有时只是对数据列的数量和类型的描述. 我知道行数是一个因素,但是即使只有几行,我也只能得到描述. 例如: 如果我有一个名为"allpledges"的DataFrame,它会给我一个描述

This is likely very simple but I can't figure out what's wrong. I am having trouble listing elements of a DataFrame. Sometimes the elements of a DataFrame are listed and sometimes it's simply a description of the number and types of the data columns. I know that the number of rows is a factor but even when I have only a few rows, I only get the description back. For example: If I have a DataFrame called 'allpledges', it gives me a description

In [5]:

allpledges

Out[5]:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 305384 entries, 0 to 305383
Data columns:
Pledge#       305384  non-null values
Source        305384  non-null values
Date          305384  non-null values
Break         305384  non-null values
Progcode      237002  non-null values

这是可以理解的,因为要显示的行太多. 但是当我尝试查看一些内容时,它仍然带给我相​​同的东西

Which is understandable because it's too many rows to display. But when I try to view a few, it still gives me the same thing

In [13]:

allpledges[:5]

Out[13]:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns:
Pledge#       5  non-null values
Source        5  non-null values
Date          5  non-null values
Break         5  non-null values
Progcode      0  non-null values

当我想要的是列出的前五行.我已经在教程中看到了这一点,但是在这里找不到我做错了什么.

When what I wanted was the top five rows listed out. I have seen this done in tutorials, but can't figure out what I am doing wrong here.

推荐答案

这些设置在

These settings are controlled in the options (I suspect you're looking for max_rows or max_columns, but there are many options seen in the set_options docstring):

In [11]: pd.options.display.max_columns
Out[11]: 20

并使用set_option进行更改:

In [12]: pd.set_option('display.max_columns', 10)

如果DataFrame 任一的列数或行数多于这些设置,则将其缩写.

If the DataFrame either has more columns or more rows than these settings it will abbreviate.

例如:

In [17]: df = pd.DataFrame(pd.np.arange(10).reshape(5,2))

In [18]: pd.set_option('display.max_rows', 4)

In [19]: df
Out[19]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns:
0    5  non-null values
1    5  non-null values
dtypes: int64(2

这篇关于列表元素与数据框描述何时发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆