serhii.net

In the middle of the desert you can say anything you want

03 May 2023

Pandas and jupyter basics I keep looking for: display all rows/cols and make cells 100% wide

# Display all columns and rows:
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
# Don't truncate values
pd.set_option('display.max_colwidth', None)

This of course works:

with pd.option_context('display.max_colwidth', None):
  display(df)

Make cells 100% wide in Jupyter:

from IPython.core.display import display, HTML 
display(HTML("<style>.container { width:100% !important; }</style>"))

And https://stackoverflow.com/a/51593236 has this function remarkably similar to the old one I’ve had, except that I changed print->display:

def print_full(x):
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 2000)
    pd.set_option('display.float_format', '{:20,.2f}'.format)
    pd.set_option('display.max_colwidth', None)
    #print(x)
	display(x)
    pd.reset_option('display.max_rows')
    pd.reset_option('display.max_columns')
    pd.reset_option('display.width')
    pd.reset_option('display.float_format')
    pd.reset_option('display.max_colwidth')

Pandas convert column to categorial

pd.row_name.astype('category')

Pandas select numeric columns1:

ds.select_dtypes(include=[np.number])

Pandas divide columns by other column2:

(ds.T / ds.col2.T).T

python - Divide multiple columns by another column in pandas - Stack Overflow


3D plotting in matplotlib: Three-Dimensional Plotting in Matplotlib | Python Data Science Handbook & the official docu: 3D plotting — Matplotlib 3.7.1 documentation

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus