I faced a problem while printing pandas dataframes in jupyter notebook. If the column names are really long it breaks the dataframe structure in different lines.
How can I print it like the way jupyter notebook does it by default(Shown in image - third cell)? As far as I know, only way to print the dataframe in bordered table style, you have to leave the variable name as the last command of the notebooks cell.
Here's the code if you want to check it,
d = pd.DataFrame({'A1_column':[1, 2, 4], 'B1_column':['a', 'b', 'd'], 'A2_column':[1, 2, 4], 'B2_column':['a', 'b', 'd'], 'A3_column':[1, 2, 4], 'B3_column':['a', 'b', 'd'], 'A4_column':[1, 2, 4], 'B4_column':['a', 'b', 'd'], 'A5_column':[1, 2, 4], 'B5_column':['a', 'b', 'd'], 'A6_column':[1, 2, 4], 'B6_column':['a', 'b', 'd'], 'A7_column':[1, 2, 4], 'B7_column':['a', 'b', 'd']}) print(d) d
Jupyter Notebook can print the output of each cell just below the cell. When you have a lot of output you can reduce the amount of space it takes up by clicking on the left side panel of the output. This will turn the output into a scrolling window.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable.
Luckily, there's a Jupyter setting that you can change to print multiple outputs. The ast_node_interactivity setting allows you to choose which results are shown as outputs. By setting it to 'all', every assign and expression will be shown.
You can use IPython's display
function to achieve that:
from IPython.display import display display(d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With