- Packages are collection of modules and sub-packages
- Modules are single python file
- Modules represent individual python files from which we can import functions
and classes.
-
-
-
-
-
-
-
-
-
-
-
-
Absolute paths start from the top-level directory in a package (usually the
package name) and travel downwards until we reach the desired sub-package or
module to import
Relative paths only work when a file imports from other files in the same
package, and will not work for importing files from other packages. However they
allow the programmer to specify a path in relation to the current file, instead of
specifying the path from the top-level directory.
We also discuss the __init__ file which serves as a marker indicating that files in
a directory are allowed to be imported.
__init__.py files are often blank though they can also specify the specific import
rules desired by the programmer.
it’s important to properly contain code in functions (including main functions) to
avoid unintended code being run.
Pip allows us to easily install Python packages from remote repositories so we
may include them in our own code. We go over several useful pip commands to
help manage our packages.
Pip also allows us to install a list of packages from a requirements file, usually
named requirements.txt. We can use the command pip install -r
requirements.txt to install from a file.
API stands for Application Programming Interface
API enables interaction through predefined methods
It acts as a standardized bridge for communication between different software
applications
REST stands for Representational State Transfer
REST (Representational State Transfer) is a set of guidelines for building
scalable web services.
- REST principles: stateless, has client server independent, cacheable, uniform
interface, and layered system
- A Rest API is a web service adhering to rest principles and returns HTTP
responses with data
- HTTP Methods include GET, POST, PUT, DELETE
- HTTP Status codes describe the outcome of a call to an API.
- API Endpoints is public URLs to access resources
- JSON is short for Javascript Object Notation
- JSON is similar to Python dictionaries, consisting of key-value pairs
- JSON Characteristics: Strings enclosed in double quotes, Keys in key-value pairs
must be strings, no trailing commas in objects
- json.loads used to convert JSON string into Python Dictionary
- json.dumps used to convert Python Dictionary into JSON string
- .json can automatically get the json object out of information
- The requests.gets() is used to retrieve data from an API.
- Numpy is a general-purpose array-processing package
- NumPy arrays are created using the np.array()function. They can be created
from Python sequences such as lists and tuples.
- Every NumPy array has a data type (dtype) that determines the type of values
stored in the array. NumPy can automatically detect the data type or you can
specify it explicitly while creating the array.
- import numpy as np
- x = np.array([1, 2])
- print(x.dtype)
- Plotting functions expect numpy.array or numpy.ma.masked_array as input,
- NumPy is faster than python lists
- NumPy is designed for efficient numerical computation.
Homogenous: all elements have the same data type.
Fixed Size: Defined upon creation.
Vectorized Operations: Fast arithmetic and mathematical operations without
using for loops
- np.arrange arrange the list in ascending numerical order.
- np.random.rand generates random arrays
- Use lists when handling mixed data types or general programming tasks.
- plt.plot(x , y)
- If you put in data as a python list matplotlib converts it automatically into
numpy array
- Typical workflow:
- Load data from JSON
- Convert it to NumPy arrays
- Use Matplotlib to visualize the results
-