2016-12-27 45 views
1

我试图在custom.js上插入此脚本。我改变所有负面货币的红色。如何将JavaScript代码插入Jupyter

我希望它适用于Jupyter上打印的所有熊猫数据框。将它添加到jupyter/anaconda文件夹中的所有custom.js后,它仍然不会改变任何内容。有人能帮我吗?

var allTableCells = document.getElementsByTagName("td"); 
for(var i = 0, max = allTableCells.length; i < max; i++) { 
    var node = allTableCells[i]; 

    //get the text from the first child node - which should be a text node 
    var currentText = node.childNodes[0].nodeValue; 

    //check for 'one' and assign this table cell's background color accordingly 
    if (currentText.includes("$ -")) 
     node.style.color = "red"; 
} 

回答

2

use the jupyter javascript magic

%%javascript 
var allTableCells = document.getElementsByTagName("td"); 
for(var i = 0, max = allTableCells.length; i < max; i++) { 
    var node = allTableCells[i]; 

    //get the text from the first child node - which should be a text node 
    var currentText = node.childNodes[0].nodeValue; 

    //check for 'one' and assign this table cell's background color accordingly 
    if (currentText.includes("$ -")) 
     node.style.color = "red"; 
} 
+0

谢谢!它在我把它放在最后一个单元格上时工作。每次运行单元格时,jupyter是否可能加载此脚本? – nicmano