Pretty-print an entire Pandas Series / DataFrame

后端 未结 12 2534
再見小時候
再見小時候 2020-11-22 03:26

I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reduced sample, with some head and tail values, but the res

12条回答
  •  天命终不由人
    2020-11-22 04:04

    Scripts

    Nobody has proposed this simple plain-text solution:

    from pprint import pprint
    
    pprint(s.to_dict())
    

    which produces results like the following:

    {'% Diabetes': 0.06365372374283895,
     '% Obesity': 0.06365372374283895,
     '% Bachelors': 0.0,
     '% Poverty': 0.09548058561425843,
     '% Driving Deaths': 1.1775938892425206,
     '% Excessive Drinking': 0.06365372374283895}
    

    Jupyter Notebooks

    Additionally, when using Jupyter notebooks, this is a great solution.

    Note: pd.Series() has no .to_html() so it must be converted to pd.DataFrame()

    from IPython.display import display, HTML
    
    display(HTML(s.to_frame().to_html()))
    

    which produces results like the following:

提交回复
热议问题