从 pandas 的数据框中的所有列输出数据 [英] Output data from all columns in a dataframe in pandas

查看:101
本文介绍了从 pandas 的数据框中的所有列输出数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为params.csv的csv文件.我打开ipython qtconsole并使用以下命令创建了熊猫dataframe:

I have a csv file with the name params.csv. I opened up ipython qtconsole and created a pandas dataframe using:

import pandas
paramdata = pandas.read_csv('params.csv', names=paramnames)

其中,paramnames是字符串对象的python列表. paramnames的示例(实际列表的长度为22):

where, paramnames is a python list of string objects. Example of paramnames (the length of actual list is 22):

paramnames = ["id",
"fc",
"mc",
"markup",
"asplevel",
"aspreview",
"reviewpd"]

在ipython提示符下,如果我键入paramdata并按Enter,则不会获得列和值的数据框,如

At the ipython prompt if I type paramdata and press enter then I do not get the dataframe with columns and values as shown in examples on Pandas website. Instead, I get information about the dataframe. I get:

In[35]: paramdata
Out[35]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 59 entries, 0 to 58
Data columns:
id                    59  non-null values
fc                    59  non-null values
mc                    59  non-null values
markup                59  non-null values
asplevel              59  non-null values
aspreview             59  non-null values
reviewpd              59  non-null values

如果键入paramdata['mc'],则可以得到mc列的预期值.我有两个问题:

If I type paramdata['mc'] then I do get the values as expected for the mc column. I have two questions:

(1)在pandas网站上的示例中(例如,在此处查看df的输出: http://pandas.sourceforge.net/indexing.html#additional-column-access ),键入数据框的名称即可得到实际数据.为什么我要获得有关上述数据框而不是实际数据的信息?我需要在某个地方设置一些输出选项吗?

(1) In the examples on the pandas website (see, for example, the output of df here: http://pandas.sourceforge.net/indexing.html#additional-column-access) typing the name of the dataframe gives the actual data. Why am I getting information about the dataframe as shown above instead of the actual data? Do I need to set some output options somewhere?

(2)如何将数据框中的所有列输出到屏幕,而不必键入其名称,即不必键入类似paramdata[['id','fc','mc']]的内容.

(2) How do I output all columns in the dataframe to the screen without having to type their names, i.e., without having to type something like paramdata[['id','fc','mc']].

我正在使用pandas版本0.8.

I am using pandas version 0.8.

谢谢.

推荐答案

屏幕上无法显示太多数据,因此将显示摘要.

There is too much data to be displayed on the screen, therefore a summary is displayed instead.

如果您仍然想输出数据(它可能无法在屏幕上显示,并且看起来也不太好):

If you want to output the data anyway (it won't probably fit on a screen and does not look very well):

print paramdata.values

将数据帧转换为其numpy-array矩阵表示形式.

converts the dataframe to its numpy-array matrix representation.

paramdata.columns

存储相应的列名和

paramdata.index

存储相应的索引(行名).

stores the respective index (row names).

这篇关于从 pandas 的数据框中的所有列输出数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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