Jupyter Notebooks

Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

JupyterLab is the next-generation user interface for Project Jupyter. It offers all the familiar building blocks of the classic Jupyter Notebook (notebook, terminal, text editor, file browser, rich outputs, etc.) in a flexible and powerful user interface.

Setup Jupyter Notebook

Install Jupyter Notebook with the following command. Alternatively, it is already packaged and ready to use with the Anaconda distribution.

pip install jupyter

Starting the Notebook Server:

jupyter notebook

Open a specific Notebook:

jupyter notebook notebook.ipynb

Setup JupyterLab

Install JupyterLab with the following command.

pip install jupyterlab

Launch by running:

jupyter lab

Useful IPython commands

The %matplotlib inline command is an IPython magic function that sets the output …

Continue reading »

React

React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called “components”.

Setup

Best way to set up React is via NodeJS package manager npm. Go to nodejs.org and download NodeJS (LTS version is recommended). It is also recommended to install React Developer Tools

To start a project we use the create-react-app tool. By using npx we run the create-react-app script without installing. Using npm will install the create-react-app package globally.

mkdir my-app
npx create-react-app .
npm start

This creates the following project structure:

my-app ├── README.md ├── node_modules ├── package.json <-- app info and dependencies ├── .gitignore ├── public │ ├── favicon.ico │ ├── index.html <-- main webpage where React is outputed │ └── manifest.json └── src ├── App.css ├── App.js <-- App component ├── App.test.js ├── index.css ├── index.js <-- React entry point ├── logo.svg └── serviceWorker.js

Continue reading »

Create a REST API with Django Rest Framework

References:

Continue reading »

Anaconda

Add a folder to the Anaconda path

By adding a folder to the Anaconda path you can call its Python scripts from any location in the Anaconda Prompt.

cd your_folder
conda-develop .

or

conda-develop /path/to/module/

https://stackoverflow.com/a/37008663/5240904

Continue reading »

Visual Studio Code setup

Themes

General use extensions

Python extensions

  • Python - Linting, Debugging, Intellisense, formatting, etc

LaTeX extensions

  • LaTeX Workshop - LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more
  • LaTeX Utilities - Add-on to LaTeX Workshop that provides some extra, non-essential, features.

HTML/CSS/Javascript

  • Live Server - Launch a development local Server with live reload feature for static & dynamic pages
  • Debugger for Chrome - Debug your JavaScript code in the Chrome browser
  • Prettier - Code formatter

Markdown

Continue reading »

VSCode shortcuts for Windows

Open/View

Open Command Pallete

Shift+Ctrl+P

Access Settings

Ctrl+,

Toggle Terminal

Ctrl+`

Create New Terminal

Shift+Ctrl+`

Toggle Sidebar

Ctrl+B

Open New Window/Instance

Shift+Ctrl+N

Close Window

Ctrl+W

Working With Files

Sidebar Focus

Shift+Ctrl+E

Open File/Folder From Sidebar

Ctrl+Down

Change File Tabs

Ctrl+PageUP

Quick File Open

Ctrl+P

Open File From Explorer

Ctrl+O

New File

Ctrl+N

Save

Ctrl+S

Save As

Shift+Ctrl+S

Close File

Ctrl+W

Delete File

Ctrl+Delete

Reopen Files

Shift+Ctrl+T

Zoom

Ctrl++ # Zoom in
Ctrl+- # Zoom out

Spilt Editor

Ctrl+\

Code Editing

Go To Start & End Of Line

Ctrl+Right
Ctrl+Left

home
end

Move By Word

Alt+Right
Alt+Left

Go To Start & End Of File

Ctrl+Home
Ctrl+End

Cut, Copy & Past Line

Ctrl+X # Cut
Ctrl+C # Copy
Ctrl+V # Paste

Move Line Up & Down

Alt+Up …

Continue reading »

Geo ploting with Basemap

The matplotlib basemap toolkit is a library for plotting 2D data on maps in Python.

Installation

Option 1:

The recommended installation method for Basemap is using Anaconda and the conda-forge channel. In the Anaconda Prompt run:

$ conda install -c anaconda basemap

You might also need to run the following command to install PROJ, which is a required dependency of Basemap:

$ conda install -c conda-forge proj

If the installation was sucessful you should now be able to run the following import in the Python (Anaconda) prompt without any errors:

from mpl_toolkits.basemap import Basemap

Option 2:

If you are on Windows you can also install the binaries directly. This worked better for me than installing through Anaconda and conda-forge. Download the Basemap and PROJ binaries. Make sure you download the correct binary for your Python version. For instance, if you have Python 3.7 64-bit make sure to download the pyproj …

Continue reading »

Data Visualization

Plotting libraries

  • Matplotlib: Python de facto 2D plotting library.

  • seaborn: Based on matplotlib, it provides a high-level interface for drawing attractive and informative statistical graphics.

  • Altair: A declarative statistical visualization library for Python, based on Vega and Vega-Lite

Web ready

  • Bokeh : Creates interactive, web-ready plots, which can be easily output as JSON objects, HTML documents, or interactive web applications.

  • Plotly: Makes interactive plots, but it offers some charts you won’t find in most libraries, like contour plots, dendograms, and 3D charts.

Geo

  • Folium: Folium makes it easy to visualize data that’s been manipulated in Python on an interactive leaflet.js map.

  • Basemap: A matplotlib toolkit library for plotting 2D data on maps in Python.

Continue reading »

Graphical user interface in Python

For simple command line programs

  • Gooey - Turn (almost) any Python command line program into a full GUI application

GUI libraries

  • TkInter - Python’s de-facto standard GUI available in the standard library

  • PySimpleGUI - Transforms tkinter, Qt, Remi, WxPython into portable people-friendly Pythonic interfaces

  • Kivy - Cross-platform GUI library supporting both desktop operating systems (Windows, macOS, Linux) and mobile devices (Android, iOS).

  • PyQt5, QtPy, PySide - There are Python bindings available for the Qt toolkit (using either PyQt or PySide). PyQt is currently more mature than PySide, but you must buy a PyQt license if you want to write proprietary applications. PySide is free for all applications.

Other

  • Streamlit - Makes it easy to build beautiful apps for machine learning.

Continue reading »

Argument parsing using the argparse module

argparse is a Python Standard Library module to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments

Initialize

import argparse

# Instantiate the parser
parser = argparse.ArgumentParser(prog='Optional app name', 
                                 description='Optional app description', 
                                 epilog='Enjoy the program!')

By default, the argparse uses the value of the sys.argv[0] element to set the name of the program (name of the Python script). However, you can specify the name of your program just by using the prog keyword.

You can customize the text displayed before and after the arguments help text using the description and epilog keywords.

Add Arguments

# Required positional argument
parser.add_argument('pos_arg', type=int,
                    help='A required integer positional argument')

# Optional positional …

Continue reading »