Python/Jupyter: Difference between revisions

From Wiki
No edit summary
No edit summary
Line 1: Line 1:
= Magic Functions =
==  Timing ==
* %timeit (time line)
* %%timeit (time block in lines below, same line = not timed setup)
== importing other jupyter notebook ==
* run.ipynb:
<blockquote>
<pre>
% run 'lib_testprog.ipynb'
testfunct()
</pre>
</blockquote>
* lib_testprog.ipynb:
<blockquote>
<pre>
def testfunct()
    return 1
if __name__ == '__main__' and '__file__' not in globals():
    print(testfunct())
</pre>
</blockquote>
== sharing variables between notebooks ==
* test1.ipynb:
<blockquote>
<pre>
variable = 'testdata'
%store variable
</pre>
</blockquote>
* test2.ipynb:
<blockquote>
<pre>
%store -r variable
print(variable)
</pre>
</blockquote>
= Initial Setup =
== Installation ==
== Installation ==
* apt install python3-pip
* apt install python3-pip
Line 4: Line 48:
* pip3 install jupyter
* pip3 install jupyter


== Magic Functions ==
* %timeit (time line)
* %%timeit (time block in lines below, same line = not timed setup)


== Config ==
== Config ==
Line 51: Line 92:
* Toggle all line numbers
* Toggle all line numbers


== importing other jupyter notebook ==
= Other Information =
* run.ipynb:
<blockquote>
<pre>
% run 'lib_testprog.ipynb'
testfunct()
</pre>
</blockquote>
 
* lib_testprog.ipynb:
<blockquote>
<pre>
def testfunct()
    return 1
 
if __name__ == '__main__' and '__file__' not in globals():
    print(testfunct())
</pre>
</blockquote>
 
== sharing variables between notebooks ==
* test1.ipynb:
<blockquote>
<pre>
variable = 'testdata'
%store variable
</pre>
</blockquote>
 
* test2.ipynb:
<blockquote>
<pre>
%store -r variable
print(variable)
</pre>
</blockquote>
 
== Links ==
== Links ==
* https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/
* https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/

Revision as of 16:16, 4 January 2018

Magic Functions

Timing

  • %timeit (time line)
  • %%timeit (time block in lines below, same line = not timed setup)

importing other jupyter notebook

  • run.ipynb:
% run 'lib_testprog.ipynb'
testfunct()
  • lib_testprog.ipynb:
def testfunct()
    return 1

if __name__ == '__main__' and '__file__' not in globals():
    print(testfunct())

sharing variables between notebooks

  • test1.ipynb:
variable = 'testdata'
%store variable
  • test2.ipynb:
%store -r variable
print(variable)


Initial Setup

Installation

  • apt install python3-pip
  • pip3 install --upgrade pip
  • pip3 install jupyter


Config

  • full width:
    • ~/.jupyter/custom/custom.css
.container { width:100% !important; }
  • autostart from rc.local
sudo -u pi /usr/local/bin/jupyter-notebook --config=/home/pi/.jupyter/jupyter_notebook_config.py


  • insecure access without token/password (/home/pi/.jupyter/jupyter_notebook_config.py)
c.NotebookApp.ip = '*'
c.NotebookApp.notebook_dir = '/srv/Python'
c.NotebookApp.open_browser = False
c.NotebookApp.password = ''
c.NotebookApp.token = ''

nbextensions

pip3 install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
  • codefolding
  • Codefolding in editor
  • Collapsible Headings
  • Table of contents
  • Variable inspector
  • Toggle all line numbers

Other Information

Links