4

I'm having a basic problem with df.head(). When the function is executed, it usually displays a nice HTML formatted table of the top 5 values, but now it only appears to slice the dataframe and outputs like below:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns (total 9 columns):
survived    5  non-null values
pclass      5  non-null values
name        5  non-null values
sex         5  non-null values
age         5  non-null values
sibsp       5  non-null values
parch       5  non-null values
fare        5  non-null values
embarked    5  non-null values
dtypes: float64(2), int64(4), object(3)

After looking at this thread I tried

pd.util.terminal.get_terminal_size()

and received the expected output (80, 25). Manually setting the print options with

pd.set_printoptions(max_columns=10)

Yields the same sliced dataframe results like above.

This was confirmed after diving into the documentation here and using the

get_option("display.max_rows")
get_option("display.max_columns")

and getting the correct default 60 rows and 10 columns.

I've never had a problem with df.head() before but now its an issue in all of my IPython Notebooks.

I'm running pandas 0.11.0 and IPython 0.13.2 in google chrome.

Community
  • 1
  • 1
agconti
  • 17,780
  • 15
  • 80
  • 114
  • Thanks for reporting, y-p has put together [a pull-request](https://github.com/pydata/pandas/pull/3657) to correct this behaviour, if you'd like to test it. I'm pretty sure we'll be able to get this 11.1 (out in a few days). – Andy Hayden May 20 '13 at 21:14
  • @AndyHayden Great, I'll test it first thing tomorrow. Thanks! – agconti May 20 '13 at 22:01

2 Answers2

4

In pandas 11.0, I think the minimum of display.height and max_rows (and display.width and max_columns`) is used, so you need to manually change that too.

I don't like this, I posted this github issue about it previously.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
2

Try using the following to display the top 10 items

from IPython.display import HTML 
HTML(users.head(10).to_html())

I think pandas 11.0 head function is totally unintuitive and should simply have remained as head() and you get your html.

emuchogu
  • 21
  • 1
  • Thank you for your idea, I'll look into it. I believe that the pandas developers have fixed this issue and made it more intuitive in pandas 11.1 – agconti May 31 '13 at 14:26