我正在Jupyter笔记本中编写一些函数来准备数据,但它们可能需要很长时间才能运行。
In [*]: print "hello"
df['expensive_col'] = df.apply(myfunc, axis=1)
如果myfunc
打印状态信息以便我看到执行的程度有多大,那将会非常有用。这样做的缺点是它会严重混乱Jupyter输出单元。
In [*]: print hello
df['expensive_col'] = df.apply(myfunc, axis=1)
hello
ix0
ix1
ix2
...
ix999
...
noisy output
...
有没有办法从长时间运行的Jupyter单元打印状态更新,以防止输出单元混乱?
例如,我可以通过调用IPython.display.clear_output()
来擦除所有打印的内容,但我可能想要进行更有针对性的擦除,在我的代价之前保留一些东西(你好,在上面的例子中)。
答案 0 :(得分:1)
您可以做的一件简单的事情是调用@IBAction func phoneNumberButtonTouched(_ sender: Any) {
if let number = place?.phoneNumber {
makeCall(phoneNumber: number)
}
}
func makeCall(phoneNumber: String) {
let formattedNumber = phoneNumber.components(separatedBy:
NSCharacterSet.decimalDigits.inverted).joined(separator: "")
let phoneUrl = "tel://\(formattedNumber)"
let url:NSURL = NSURL(string: phoneUrl)!
if #available(iOS 10, *) {
UIApplication.shared.open(url as URL, options: [:], completionHandler:
nil)
} else {
UIApplication.shared.openURL(url as URL)
}
}
函数,并将print
参数设置为回车符而不是换行符,如下所示:
end
它有效地写入前一行,而不会使输出字段混乱。
要获得更高级的方法(并且看上去很棒!)查看tqdm project。