Create a file

Type in shell/terminal:

touch file_name.py

or

nul > file_name.py

or using echo command

echo. > file_name.py

mkdir name_of_directory

PATH variable

PATH is an environmental variable

tells which directories to search

for executable files, use echo to see PATH

echo $PATH

add a directory to a PATH variable

PATH="directory:${PATH}"

export PATH

PIP

pip is a package management system

Mac:

sudo easy_install pip

WIndows - save get-pip.py from this link:

http://pip.readthedocs.io/en/stable/

launch file:

python get-pip.py

Virtual Environment

is a tool to create isolated environment

Mac - Install virtualenv:

sudo pip install virtualenv

or if you get an error:

sudo -H pip install virtualenv

Windows - Install virtualenv:

pip install virtualenv

Open a page in a new window

To open a link in a new window, use:

target="_blank"

in the <a href="link> tag

links are defined with the <a> tag

Git Discard, Delete, Unstage

Discard the local changes:

git reset --hard

Stash it, Stashing acts as a stack:

git stash pop

Removing directory from repository:

git rm -rf cached_directory

git rm --cached file

Check version

Check Python version:

python -V

Check Anaconda version:

conda -V

Check all Python libraries:

pip freeze

pip list

reverse vs reverse_lazy

reverse() function:

Like url tag defines a hyperlink by 'name'

reverse_lazy() function:

Prevents error when URL Conf is not loaded

Provides url of a generic class-based view

Often used as success url

success_url = reverse_lazy('name')

Check the error logs for Apache

You can check the error logs for Apache

in /var/log/apache2

tail -20 error.log

This command will return 20 last rows

from error.log

NumPy array

Create NumPy array:

numpy.array(object)

NumPy array is a data structure

more convenient and efficient than a list

Faster in reading and writing

The sum on the NumPy array is 10x faster

than Python list

Change a column name

Change a specified column name in a DataFr

df.rename(columns = {'old':'new'})

or

df.columns.values[1] = "new"