ipython

How to set a base url for markdown links in IPython?

放肆的年华 提交于 2019-12-10 20:13:11
问题 I was happily setting <head> <base href="http://complex_url_to_local_wiki:port/path/" target="_blank" /> </head> in a Markdown cell in my IPython html notebook (IPython 0.12) in order to be able to abbreviate links as [wiki documentation](doc.html) in Markdown cells. But this makes saving the notebook impossible (saving is restored by <base href='/'/> ). Is there any (alternative) way to achieve what I am seeking? I know how to produce the URL from Python code by use of IPython.core.display

display DataFrame() values in bold font in one row only

隐身守侯 提交于 2019-12-10 19:34:32
问题 having dataframe summary being called directly from jupyter cell summary #(Shift + Enter) how can I make the highlighted row only (last row) in bold font? 回答1: Please, please provide the code to at least generate the dataframe you are posting. For what you want, you can use style.applymap() function. The rest is to find the correct properties of font that can be set to bold and how to set index of last row. In [1]: import pandas as pd In [2]: def df_style(val): return 'font-weight: bold' In

Issue plotting vertex labels using igraph in ipython

空扰寡人 提交于 2019-12-10 19:08:17
问题 I usually work in a IPython notebook, which I open on Windows with the command ipython qtconsole --matplotlib inline I'm currently using IPython QtConsole 3.0.0, Python 2.7.9 and IPython 3.0.0. I want to plot a graph, together with its labels from igraph import * g = Graph.Lattice([4,4],nei=1,circular=False) g.vs["label"]=[str(i) for i in xrange(16)] plot(g, layout="kk") In this way, I obtain a inline plot of the graph, but there are no labels and I get the following message error for each of

如何在Python中使用线程?

强颜欢笑 提交于 2019-12-10 19:03:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我试图了解Python中的线程。 我看过文档和示例,但是坦率地说,许多示例过于复杂,我难以理解它们。 您如何清楚地显示为多线程而划分的任务? #1楼 对我而言,线程化的完美示例是监视异步事件。 看这段代码。 # thread_test.py import threading import time class Monitor(threading.Thread): def __init__(self, mon): threading.Thread.__init__(self) self.mon = mon def run(self): while True: if self.mon[0] == 2: print "Mon = 2" self.mon[0] = 3; 您可以通过打开IPython会话并执行以下操作来使用此代码: >>>from thread_test import Monitor >>>a = [0] >>>mon = Monitor(a) >>>mon.start() >>>a[0] = 2 Mon = 2 >>>a[0] = 2 Mon = 2 等一下 >>>a[0] = 2 Mon = 2 #2楼 仅需注意,线程不需要Queue。 这是我能想到的最简单的示例,其中显示了10个进程同时运行。

timing in python with %timeit %%timeit how to keep/retain values for later use

无人久伴 提交于 2019-12-10 18:38:47
问题 I am trying to measure the execution time of different parts of my code, a few lines each. I am doing this with %%timeit, however after I execute a cell, I find that the values calculated for variables in the cell are not kept in memory for next cells, as in the following example. Why does this happen? Is there a way to retain the values so I can use them in the rest of the program? In [1]: %%timeit ...: dog='dog' 100000000 loops, best of 3: 16.2 ns per loop In [2]: print (dog) --------------

iPython magic for Zipline cannot find data bundle

狂风中的少年 提交于 2019-12-10 18:18:18
问题 I have a Python 2.7 script that runs Zipline fine on the command prompt, using --bundle=myBundle to load the custom data bundle myBundle which I have registered using extension.py . zipline run -f myAlgo.py --bundle=myBundle --start 2016-6-1 --end 2016-7-1 --data-frequency=minute Problem: However when I try to use the %zipline IPython magic to run the algorithm, the bundle argument --bundle seems to have difficulty finding myBundle . %zipline --bundle=myBundle--start 2016-6-1 --end 2016-7-1 -

drop into an interactive session to examine a failed unit test

寵の児 提交于 2019-12-10 18:16:54
问题 I'd like to be able to enter an interactive session, preferably with IPython, if a unit test fails. Is there an easy way to do this? edit : by "interactive session" I mean a full Python REPL rather than a pdb shell. edit edit : As a further explanation: I'd like to be able to start an interactive session that has access to the context in which the test failure occurred. So for example, the test's self variable would be available. 回答1: In IPython, use %pdb before running the test In [9]: %pdb

ipython %timeit “local variable 'a' referenced before assignment”

穿精又带淫゛_ 提交于 2019-12-10 17:53:28
问题 I am trying to the run the following code but I get a local variable 'a' referenced before assignment. a = [x for x in range(10)] b = [x for x in range(10)] %timeit a+=b The statement works without the %timeit magic. Is there something I am missing? Thank you. 回答1: What do you expect it to do? Outside of the timeit it does: In [188]: a += b In [189]: a Out[189]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] I tried initializing x , and got a near infinite loop, eventually

How to pass a variable as a command line argument in iPython?

拥有回忆 提交于 2019-12-10 17:46:52
问题 For example, I have a Python module and a iPython module, cmd.py import sys print sys.argv test.ipynb for i in range(5): %run cmd.py i When I run test.ipynb, it just print ['cmd.py', 'i'] multiple times. How can I pass the value of i instead of 'i' as a command line argument? 回答1: the shell mode interprets everything literally (else cmd.py would be evaluated as well). I would just do: for i in range(5): %run cmd.py $i from http://ipython.readthedocs.io/en/stable/interactive/reference.html

How to autosave ipython notebook

别等时光非礼了梦想. 提交于 2019-12-10 17:27:48
问题 Does anyone know if there's an option (or a suggested hack) to make IPython notebooks save automatically before executing a cell? Many times I've been working on something without saving for quite some time, then I execute a stupid command that prints so much crap to the console that my browser becomes unresponsive, leading to me losing all my work. A timed autosave might also do the trick. 回答1: The development version has that feature fully implemented. Install it by following the