df.head() sometimes doesn't work in Pandas, Python

后端 未结 3 835
故里飘歌
故里飘歌 2020-12-09 09:55

I\'m a beginner in Python and the Pandas library, and I\'m rather confused by some basic functionality of DataFrame. I\'ve got a pandas DataFrame as below:



        
相关标签:
3条回答
  • 2020-12-09 10:06

    Try the below code segment:

    from IPython.display import display
    display(df.head())
    
    0 讨论(0)
  • 2020-12-09 10:09
     DataFrame.head(n=5)
    

    Return the first n rows.

    This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.

    Parameters:

    n : int, default 5
    

    Number of rows to select.

    Returns:

    obj_head : type of caller
    

    The first n rows of the caller object.

    0 讨论(0)
  • 2020-12-09 10:24

    df.head(n) returns a DataFrame holding the first n rows of df. Now to display a DataFrame pandas checks by default the width of the terminal, if this is too small to display the DataFrame a summary view will be shown. Which is what you get in the second case.

    Could you increase the size of your terminal, or disable autodetect on the columns by pd.set_printoptions(max_columns=10)?

    0 讨论(0)
提交回复
热议问题