-
Notifications
You must be signed in to change notification settings - Fork 0
Python
$ sudo apt install python3-pip python3-dev
$ pip3 install --user pipenv
$ echo "PATH=$HOME/.local/bin:$PATH" >> ~/.bashrc
$ source ~/.bashrc
$ pip install jupyter
First start an IPython notebook session on your remote machine, with the --no-browser and --port=7777 options
$ ipython notebook --no-browser --port=7777
Then we set up the ssh tunnel from the local machine to the remote machine
$ ssh -N -f -L localhost:7777:localhost:7777 dh@68.137.6.28
(Note: on mac to find and kill the background ssh process, just do
$ ps -ax | grep ssh
$ kill #PID
Go to localhost:7777 on your local browser and start using remotely hosted IPython notebooks.
On the server, run
$ jupyter notebook --ip=server_machine.local
It will give an URL, then just go to that URL through the browser on your local machine.
You can just do
cd $work_dir
in your IPython code.
Go to link.
>>> df.CompanyGroup.value_counts()
itertuples() is about 60 times faster than iterrows() when iterating through the rows of a Pandas dataframe
>>> df = pd.DataFrame({'a': randn(1000), 'b': randn(1000),'N':randint(100, 1000, (1000)), 'x': 'x'})
>>> %timeit [row.a * 2 for idx, row in df.iterrows()] # => 10 loops, best of 3: 50.3 ms per loop
>>> %timeit [row[1] * 2 for row in df.itertuples()] # => 1000 loops, best of 3: 541 µs per loop
For the python interractive environment to work with up and down keystrokes, you need to install the readline package,
$ pip install readline
There is no request object in urllib as in section 3.1 in the nltk book. Instead we can directly call the urlopen method in urllib
>>> url = "http://www.gutenberg.org/files/2554/2554.txt"
>>> response = urllib.urlopen(url)
-
sklearn/scikit(best) pylearn2
$ sudo apt-cache search freetype | grep dev
$ sudo apt-get install libfreetype6-dev
$ python -m pip install matplotlib
$ python -m pip install pydot2
Download nltk in the python command-line
$ python
>>> import nltk
>>> nltk.download('all')
Make sure you have the lastest version of nltk because it is constantly maintained
$ python -m pip install --upgrade nltk
$ brew tap homebrew/science
$ brew install megam
The store_true option automatically creates a default value of False. Likewise, store_false will default to True when the command-line argument is not present. For example
>>> parser.add_argument('-p', '--param', action='store_true')
param will default to false if -p is not present.
>>> dir(obj)
>>> import os
>>> os.listdir('.')
Use raw_input() instead of the input() method as in nltk book section 3.1.
If we have made some changes to a function func inside a module, we can reload the function by
>>> reload(module)
>>> from module import func
or
>>> import imp
>>> imp.reload(module)
See page.
>>> foo = u'Δ, Й, ק, م, ๗, あ, 叶, 葉, and 말.'
>>> with open('test', 'w') as f:
f.write(foo.encode('utf8'))
When you read that file, you'll get a unicode-encoded string that you can decode to a unicode object
>>> with open('test', 'r') as f:
print f.read().decode('utf8')
To measure time for a calculation in python, e.g. calculate cosine distances, do
>>> timeit.timeit('cosine(a,b)',setup="from scipy.spatial.distance import cosine; import numpy as np; a = np.random.rand(1,136702); b = np.random.rand(1,136702)",number=1000)
The frozenset() method returns an immutable frozenset object initialized with elements from the given iterable.
Frozen set is just an immutable version of a Python set object. While elements of a set can be modified at any time, elements of frozen set remains the same after creation.
Due to this, frozen sets can be used as key in Dictionary or as element of another set. But like sets, it is not ordered (the elements can be set at any index).