Reputation: 1541
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
Upvotes: 43
Views: 59288
Reputation: 3595
You can use IPython's display
function to achieve that:
from IPython.display import display
display(d)
Upvotes: 57