1 - Default look of pandas sheet¶
note: style is default style
In [84]:
import pandas as pd
df = pd.read_csv("test.csv")
df.style
Out[84]:
2 - With background color¶
In [32]:
import pandas as pd
df = pd.read_csv("test.csv")
df.head().style.set_properties(**{'background-color': 'grey',
'color': 'yellow',
'border-color': 'red'})
Out[32]:
3 - With color axis and highlight¶
In [71]:
import pandas as pd
df = pd.read_csv("test.csv")
df.head().style.set_table_styles(
[
{'selector': 'th',
'props': [('background', 'yellow'),
('color', 'black'), ]},
{'selector': 'td',
'props': [('color', 'blue')]},
{ 'selector': 'tr:hover',
'props': [('background-color', 'red')]}
])
Out[71]:
4 - Combining both set_table_styles with set_properties. Table border doesn't exist in set_table_styles¶
In [83]:
import pandas as pd
df = pd.read_csv("test.csv")
z = df.head().style.set_table_styles(
[
{'selector': 'th',
'props': [('background', 'yellow'),
('color', 'black'), ]},
{'selector': 'td',
'props': [('color', 'blue')]},
{ 'selector': 'tr:hover',
'props': [('background-color', 'orange')]}
])
z.set_properties(**{'background-color': 'grey-light',
'border-style': 'solid'})
Out[83]:
5 - The following will overwrite entire notebook with thick border¶
In [75]:
%%HTML
<style type="text/css">
table.dataframe td, table.dataframe th {
border-style: solid;
background-color: gray-light;
}
</style>
In [40]:
import pandas as pd
df = pd.read_csv("test.csv")
df.head()
Out[40]:
References