I'm probably have a simple question but I can't seem to find a solution online. If I create a dataframe "df" in a Jupyter notebook and then I print it out using print(), the table displayed in my broswer does not show any borders at all. For example:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(5,2), columns=["a","b"])
print(df)
This will show a table with no border. I read Jupyter pandas.DataFrame output table format configuration but that seems to help if I simply type
df.head()
not the output of the print() function. Does somebody have any suggestions? Many thanks
You can use the print() method to print the dataframe in a table format. You can convert the dataframe to String using the to_string() method and pass it to the print method which will print the dataframe.
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.
Set the figure size and adjust the padding between and around the subplots. Make a Pandas dataframe with straight and square keys. Create a new figure or activate an existing figure using figure() method.
Print the data In a Jupyter notebook, simply typing the name of a data frame will result in a neatly formatted outputs. This is an excellent way to preview data, however notes that, by default, only 100 rows will print, and 20 columns.
@Angel, you can add this script in any cell to introduce table borders. Use df
instead of print(df)
%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
border: 1px black solid !important;
color: black !important;
}
</style>
Instead of print(df) you use:
from IPython.display import display
display(df)
The answer of @MEdwin is perfect, just need to close the style tag, otherwise the broken HTML results in 'eated up' output of several output cells, which follows the HTML code.
%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
border: 1px black solid !important;
color: black !important;
}
</style>
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