Skip to main content
Beta
This lesson is in the beta phase, which means that it is ready for teaching by instructors outside of the original author team.
Key Points
- Assign values to variables using
=
- Generate lists using square brackets
[]
- Use indexes inside
[], starting at 0, to select
characters from strings and items from lists
- Use
for to loop through items in iterable objects
- Make conditional expressions using
==, !=,
>, <, >= and
<=
- Use
f'{}' to embed formatted variables inside
strings
- Avoid use of generative AI for this course
- JSON is a simple, easy to interpret format for unstructured
data
- Dictionaries are defined using
key:value
pairs
- Dictionaries can be nested, and mixed with lists
- Web API’s can be accessed using the
requests
library
- NumPy arrays are not matrix objects
- Array masks can be created using conditional statements
- NumPy arrays can be masked to hide data you don’t want to include in
an analysis
- NumPy libraries are available for reading a lot of different file
formats
-
try-except structures are useful for catching errors as
they occur
-
assert structures are useful for forcing errors early,
to avoid wasted effort
-
astropy.units library provides unit support
-
Quantity objects are created by multiplying values by
the desired units
- The
.to() function can be used to convert units
- The
.decompose() function can be used to convert to the
base (irreducible) units
- Equivalences can be found using the
.find_equivalent_units() function
- Specific equivalence libraries can be defined using the
equivalences= keyword
- Import quantity-support from
astropy.visualization to
integrate units with matplotlib for data plotting
- The
pint library provides similar unit support, but is
better for working with temperature increments
- CSV data is loaded using the
read_csv() function to
create a pandas DataFrame object
- The
describe() function gives a quick analysis of the
DataFrame
-
loc[<index>,<column>] indexes the DataFrame
by the index and column labels
-
iloc[<index>,<column>] indexes the
DataFrame using numerical indices
- The data can be sliced by providing index and/or column indices as
ranges or lists of values
- The built-in
plot() function can be used to plot the
data using the matplotlib library
- conda virtual environments are useful for installing programs with
differing requirements
-
conda config --add channels <channel> adds a new
channel to your list of sources
-
conda search <package> will find all available
versions of a package in your list of sources
-
conda create -n <env> <package(s)> can be
used to create a virtual environment from a list of packages
-
conda install -n <env> <pacakge(s)>
installs packages in a pre-existing environment
-
conda activate <env> activates the named
environment, giving access to the software installed there
-
conda deactivate deactivates the current
environment
-
conda export --from-history > <file.yml>
creates a portable record of your current environment
-
conda env create --file <file.yml> <env>
creates a new environment from an environment file