How to force printing of DataFrame data in IPython

13,095 views
Skip to first unread message

David Hartunian

unread,
Dec 7, 2012, 10:23:05 AM12/7/12
to pyd...@googlegroups.com
When working with IPython (command line and in notebook) is there a way to force a DataFrame to be printed to the screen instead of the summary info?
I'm using pandas 0.9.1.

For example, when I run the following code:
import numpy as np
import pandas as pd
nums = np.random.rand(100,10)
df = pd.DataFrame(nums, columns = [map(chr, range(65, 65+10))])
I see the following output for df and print df in the IPython notebook:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 100 entries, 0 to 99
Data columns:
A 100 non-null values
B 100 non-null values
C 100 non-null values
D 100 non-null values
E 100 non-null values
F 100 non-null values
G 100 non-null values
H 100 non-null values
I 100 non-null values
J 100 non-null values 
dtypes: float64(10) 
In the command line I get to see the actual data inside instead of the summary view above like this:

           A         B         C         D         E         F         G         H         I         J
0   0.761324  0.032018  0.080746  0.739734  0.936926  0.664572  0.951255  0.577401  0.988688  0.573861
1   0.558247  0.237166  0.322528  0.786457  0.760680  0.410444  0.951133  0.999485  0.020494  0.189512
2   0.605848  0.362981  0.219368  0.791850  0.912985  0.976945  0.848627  0.436797  0.663344  0.598473
3   0.568639  0.272206  0.679147  0.531995  0.396008  0.690554  0.111167  0.580572  0.760094  0.349107
4   0.961384  0.994971  0.761088  0.806473  0.288171  0.068695  0.045302  0.721822  0.430187  0.793681
5   0.836996  0.118935  0.996416  0.947395  0.380154  0.819513  0.530146  0.969229  0.392297  0.957748
6   0.569859  0.706542  0.610082  0.867170  0.792394  0.933430  0.938307  0.511343  0.262208  0.369842
... etc...

Is there a way to force pandas and/or IPython to show me the DataFrame data when I print it?

Arthur Gerigk

unread,
Dec 7, 2012, 10:24:18 AM12/7/12
to pyd...@googlegroups.com
print df.to_string()


--
 
 

Skipper Seabold

unread,
Dec 7, 2012, 10:25:10 AM12/7/12
to pyd...@googlegroups.com
Have a look at pandas.set_printoptions

Skipper 

Tansu Demirbilek

unread,
Dec 7, 2012, 10:47:40 AM12/7/12
to pyd...@googlegroups.com
Aside from .to_string() which is quick and easy, I use .to_html() to create an html table. I've written a view() helper function which creates a proper html file using the table generated by pandas, embeds some Javascript code for quick filtering (which relies on jquery by the way), and kicks off my browser. This took me less than a day to write and it's an extremely powerful tool to visualize and filter tabular data. Can't share the code here but it is an easy thing to do. 

There also was a talk at pydata 2012 which I should admit I didn't watch but might be useful to grasp the concept. http://vimeo.com/53063185



--
 
 

Goyo

unread,
Dec 10, 2012, 3:17:15 AM12/10/12
to pyd...@googlegroups.com
El viernes, 7 de diciembre de 2012 16:47:40 UTC+1, TD escribió:
Aside from .to_string() which is quick and easy, I use .to_html() to create an html table. I've written a view() helper function which creates a proper html file using the table generated by pandas, embeds some Javascript code for quick filtering (which relies on jquery by the way), and kicks off my browser.

This can be done in notebook using display and HTML:

from IPython.core.display import HTML
display(HTML(df.to_html()))

Goyo

Lex H

unread,
Dec 11, 2012, 1:56:57 AM12/11/12
to pyd...@googlegroups.com
A related tip I use often, when wanting to have look at some data in a DataFrame, but the columns are too wide to fit into my display.

I run

print df.head(3).T

Which will give you a view of your data (only with rows/columns exchanged).


--
 
 

Wes McKinney

unread,
Dec 11, 2012, 6:02:16 PM12/11/12
to pyd...@googlegroups.com
On Tue, Dec 11, 2012 at 1:56 AM, Lex H <lex....@gmail.com> wrote:
> A related tip I use often, when wanting to have look at some data in a
> DataFrame, but the columns are too wide to fit into my display.
>
> I run
>
> print df.head(3).T
>
> Which will give you a view of your data (only with rows/columns exchanged).
>
>

FYI this is much nicer in pandas 0.10, very "wide" DataFrames can be
better viewed without having to transpose...
> --
>
>

Khalman Michael

unread,
Jan 13, 2014, 7:41:20 AM1/13/14
to pyd...@googlegroups.com
I think, the problem is your dataframe is too big.

I had the same problem in ipython notebook and it showed me it in a right way when I used .head(n=3) method

пятница, 7 декабря 2012 г., 19:23:05 UTC+4 пользователь David Hartunian написал:

Daniel

unread,
Jan 20, 2014, 5:55:00 PM1/20/14
to pyd...@googlegroups.com
I had that problem, but then found the solution in the FAQ:
"How do I control the way my DataFrame is displayed?"
http://pandas.pydata.org/pandas-docs/stable/faq.html
Reply all
Reply to author
Forward
0 new messages