ipython-notebook

collapse cell in jupyter notebook

删除回忆录丶 提交于 2019-11-29 19:29:40
I am using ipython Jupyter notebook. Let's say I defined a function that occupies a lot of space on my screen. Is there a way to collapse the cell? I want the function to remain executed and callable, yet I want to hide / collapse the cell in order to better visualize the notebook. How can I do this? The jupyter contrib nbextensions Python package contains a code-folding extension that can be enabled within the notebook. Follow the link (Github) for documentation. To install using command line: pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user To make life

IPython Notebook cell multiple outputs

雨燕双飞 提交于 2019-11-29 19:25:20
I am running this cell in IPython Notebook: # salaries and teams are Pandas dataframe salaries.head() teams.head() The result is that I am only getting the output of teams data-frame rather than of both salaries and teams . If I just run salaries.head() I get the result for salaries data-frame but on running both the statement I just see the output of teams.head() . How can I correct this? have you tried the display command? from IPython.display import display display(salaries.head()) display(teams.head()) Aru Singh An easier way: from IPython.core.interactiveshell import InteractiveShell

IPython Notebook - Keep printing to notebook output after closing browser

此生再无相见时 提交于 2019-11-29 18:24:23
问题 I'm doing long-running experiments in an IPython notebook running on a server, where the typical work cycle is: launch experiment, go to lunch, come back, check progress, check Facebook, check email, check Facebook again, turn off computer, come back, check Facebook, check progress, ... The problem is that when I close the browser window where the notebook is running, the print/logging outputs are no longer saved in the notebook. For instance, in my simple experiment: import time start_time =

merge two dataframes without repeats pandas

你离开我真会死。 提交于 2019-11-29 17:21:07
I am trying to merge two dataframes, one with columns: customerId, full name, and emails and the other dataframe with columns: customerId, amount, and date. I want to have the first dataframe be the main dataframe and the other dataframe information be included but only if the customerIds match up; I tried doing: merge = pd.merge(df, df2, on='customerId', how='left') but the dataframe that is produced contains a lot of repeats and looks wrong: customerId full name emails amount date 0 002963338 Star shine star.shine@cdw.com $2,910.94 2016-06-14 1 002963338 Star shine star.shine@cdw.com $9,067

old sklearn version in Jupyter Notebook

。_饼干妹妹 提交于 2019-11-29 16:44:31
I update sklearn version by terminal with conda install scikit-learn=0.18 if I list with conda list scikit-learn # packages in environment at /Users/Claudia/anaconda: scikit-learn 0.18.1 np111py27_1 scikit-learn 0.18.1 <pip> but if I run in notebook print('The scikit-learn version is {}.'.format(sklearn.__version__)) the result is The scikit-learn version is 0.17.1. How can I solve and update also the version in Jupyter Notebook? to update the version used by Jupyter you need to open terminal by Jupiter interface and run command from here conda update scikit-learn the mistake was the use of

Matplotlib pyplot.title(string) returns error

淺唱寂寞╮ 提交于 2019-11-29 16:39:49
问题 When I call pyplot.title('some string') it throws the exception, 'str' object is not callable' . I copied the following from the matplotlib online documentation: mu, sigma = 100, 15 x = mu + sigma * np.random.randn(10000) # the histogram of the data n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) plt.xlabel('Smarts') plt.ylabel('Probability') plt.title('Histogram of IQ') plt.text(60, .025, r'$\mu=100,\ \sigma=15$') plt.axis([40, 160, 0, 0.03]) plt.grid(True) plt.show()

No trigger by the name “interval” was found

好久不见. 提交于 2019-11-29 15:40:11
I've been working with APScheduler and when attempting to run the code I get the error "No trigger by the name 'interval' was found" It was perfectly on my local machine but will work on my cloud machine. I have tried: reinstalling apscheduler via pip, easy_install, and manually; upgrading setuptools; upgrading all dependencies. Edit: Code if __name__ == '__main__': scheduler = BlockingScheduler() scheduler.add_job(SMS, 'interval', minutes=1) scheduler.start() print Run Complete try: # This is here to simulate application activity (which keeps the main thread alive). while True: time.sleep(2)

secondary_y=True changes x axis in pandas

寵の児 提交于 2019-11-29 12:46:35
I'm trying to plot two series together in Pandas, from different dataframes. Both their axis are datetime objects, so they can be plotted together: amazon_prices.Close.plot() data[amazon].BULL_MINUS_BEAR.resample("W").plot() plt.plot() Yields: All fine, but I need the green graph to have its own scale. So I use the amazon_prices.Close.plot() data[amazon].BULL_MINUS_BEAR.resample("W").plot(secondary_y=True) plt.plot() This secondary_y creates a problem, as instead of having the desired graph, I have the following: Any help with this is hugely appreciated. (Less relevant notes: I'm (evidently)

Make output cells like Markdown

微笑、不失礼 提交于 2019-11-29 11:40:18
问题 I like IPython's Markdown cells for incorporating HTML and other rich content inside notebooks. I would like to know if a command output can be formatted similarly, in output cells. Here is one of my functions outputting HTML: print_html(): print """ <h2>Matplotlib's chart gallery (Click a chart to see the code to create it)</h2><br> <div align="center"> <iframe title="Matplotlib Gallery" width="950" height="250" src="http://matplotlib.org/gallery.html#api" frameborder="0" allowfullscreen><

Cannot import .py file to ipython notebook

只谈情不闲聊 提交于 2019-11-29 11:19:27
With apologies in advance for the "I can't get it to work" question: How should I load a .py file into ipython notebook? I want to convert python code to notebooks (first simple scripts and later scripts that include nbconvert directives embedded as comments -- see bottom of the linked file.) Perhaps I'm doing it wrong, but perhaps there's something wrong with my set-up. When I drag a .py file to the Notebook's file list, I get the message Invalid file type: Uploaded notebooks must be .ipynb files. I even tried changing the extension to .ipynb (keeping the python script unmodified); reasonably