I am using Jupyter Notebook and Pandas DataFrame to look through some 3D and 4D matrices. I am using what @Attack68 has replied in this question.
The problem is, when I use only one jupyter cell for making a DataFrame, without calling "display" function, it works just fine, and will run HTML codes perfectly. You can see an example here:
import pandas as pd
data = [
[[1]],
[[1.0,2.0],[2.0,4.0],[8.0,3.0],[9.0,7.0]],
[[0.487],[1.532],[1.544],[1.846]],
[[3.0]],
[[3.0]],
[[-1]],
]
df = pd.DataFrame([
[(pd.DataFrame(x)
.style
.hide_index()
.hide_columns()
.set_table_attributes('class="matrix"')
.to_html()
) for x in data]
], dtype="object")
df.style.set_table_styles([
{"selector": ".matrix", "props": "position: relative;"},
{"selector": ".matrix:before, .matrix:after",
"props": 'content: ""; position: absolute; top: 0; border: 1px solid #000; width: 6px; height: 100%;'
},
{"selector": ".matrix:before", "props": "left: -0px; border-right: -0;"},
{"selector": ".matrix:after", "props": "right: -0px; border-left: 0;"}
])
Which will result in : Intended_Result (my reputation is not enough to use inline image. Sorry about inconvenience)
However, the problem is, as soon as I add display function to display the table, it stops compiling the HTML codes and showing the matrices itself, and returns only the codes instead as the DataFrame cells.
import pandas as pd
data = [
[[1]],
[[1.0,2.0],[2.0,4.0],[8.0,3.0],[9.0,7.0]],
[[0.487],[1.532],[1.544],[1.846]],
[[3.0]],
[[3.0]],
[[-1]],
]
df = pd.DataFrame([
[(pd.DataFrame(x)
.style
.hide_index()
.hide_columns()
.set_table_attributes('class="matrix"')
.to_html()
) for x in data]
], dtype="object")
df.style.set_table_styles([
{"selector": ".matrix", "props": "position: relative;"},
{"selector": ".matrix:before, .matrix:after",
"props": 'content: ""; position: absolute; top: 0; border: 1px solid #000; width: 6px; height: 100%;'
},
{"selector": ".matrix:before", "props": "left: -0px; border-right: -0;"},
{"selector": ".matrix:after", "props": "right: -0px; border-left: 0;"}
])
display(df)
You can see the results here: Wrong_Results
Thanks.