2016-12-27 79 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

相關問題