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
pd.options.display
This answer is a variation of the prior answer by lucidyan. It makes the code more readable by avoiding the use of set_option
.
After importing pandas, as an alternative to using the context manager, set such options for displaying large dataframes:
def set_pandas_display_options() -> None:
"""Set pandas display options."""
# Ref: https://stackoverflow.com/a/52432757/
display = pd.options.display
display.max_columns = 1000
display.max_rows = 1000
display.max_colwidth = 199
display.width = None
# display.precision = 2 # set as needed
set_pandas_display_options()
After this, you can use either display(df)
or just df
if using a notebook, otherwise print(df)
.
to_string
Pandas 0.25.3 does have DataFrame.to_string and Series.to_string methods which accept formatting options.
to_markdown
If what you need is markdown output, Pandas 1.0.0 has DataFrame.to_markdown and Series.to_markdown methods.
to_html
If what you need is HTML output, Pandas 0.25.3 does have a DataFrame.to_html method but not a Series.to_html
. Note that a Series
can be converted to a DataFrame
.