How to load/edit/run/save text files (.py) into an IPython notebook cell?

EDIT: Starting from IPython 3 (now Jupyter project), the notebook has a text editor that can be used as a more convenient alternative to load/edit/save text files. A text file can be loaded in a notebook cell with the magic command %load. If you execute a cell containing: %load filename.py the content of filename.py will … Read more

Using both Python 2.x and Python 3.x in IPython Notebook

The idea here is to install multiple ipython kernels. Here are instructions for anaconda. If you are not using anaconda, I recently added instructions using pure virtualenvs. Anaconda >= 4.1.0 Since version 4.1.0, anaconda includes a special package nb_conda_kernels that detects conda environments with notebook kernels and automatically registers them. This makes using a new … Read more

Autoreload of modules in IPython [duplicate]

For IPython version 3.1, 4.x, and 5.x %load_ext autoreload %autoreload 2 Then your module will be auto-reloaded by default. This is the doc: File: …my/python/path/lib/python2.7/site-packages/IPython/extensions/autoreload.py Docstring: “autoreload“ is an IPython extension that reloads modules automatically before executing the line of code typed. This makes for example the following workflow possible: .. sourcecode:: ipython In [1]: … Read more

Progress indicator during pandas operations

Due to popular demand, I’ve added pandas support in tqdm (pip install “tqdm>=4.9.0”). Unlike the other answers, this will not noticeably slow pandas down — here’s an example for DataFrameGroupBy.progress_apply: import pandas as pd import numpy as np from tqdm import tqdm # from tqdm.auto import tqdm # for notebooks # Create new `pandas` methods … Read more

Change IPython/Jupyter notebook working directory

jupyter notebook –help-all could be of help: –notebook-dir=<Unicode> (NotebookManager.notebook_dir) Default: u’/Users/me/ipynbs’ The directory to use for notebooks. For example: jupyter notebook –notebook-dir=/Users/yourname/folder1/folder2/ You can of course set it in your profiles if needed, you might need to escape backslash in Windows. Note that this will override whatever path you might have set in a jupyter_notebook_config.py … Read more

Simple way to measure cell execution time in ipython notebook

The only way I found to overcome this problem is by executing the last statement with print. Do not forget that cell magic starts with %% and line magic starts with %. %%time clf = tree.DecisionTreeRegressor().fit(X_train, y_train) res = clf.predict(X_test) print(res) Notice that any changes performed inside the cell are not taken into consideration in … Read more

Inserting image into IPython notebook markdown

Most of the answers given so far go in the wrong direction, suggesting to load additional libraries and use the code instead of markup. In Ipython/Jupyter Notebooks it is very simple. Make sure the cell is indeed in markup and to display a image use: ![alt text](imagename.png “Title”) Further advantage compared to the other methods … Read more

In which conda environment is Jupyter executing?

As mentioned in the comments, conda support for jupyter notebooks is needed to switch kernels. Seems like this support is now available through conda itself (rather than relying on pip). http://docs.continuum.io/anaconda/user-guide/tasks/use-jupyter-notebook-extensions/ conda install nb_conda which brings three other handy extensions in addition to Notebook Conda Kernels.

How to write LaTeX in IPython Notebook?

IPython notebook uses MathJax to render LaTeX inside html/markdown. Just put your LaTeX math inside $$. $$c = \sqrt{a^2 + b^2}$$ Or you can display LaTeX / Math output from Python, as seen towards the end of the notebook tour: from IPython.display import display, Math, Latex display(Math(r’F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx’))

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)