Some more python to get you started#

# import the pandas package
import pandas as pd

# import numpy
import numpy as np

# import the package we'll use for plotting
import matplotlib.pyplot as plt

# this tells the jupyter notebook to show plots "inline" with other output here in the notebook
%matplotlib inline

Opening data files (with pandas):#

# Location of the data file
Skykomish_data_file = 'Skykomish_peak_flow_12134500_skykomish_river_near_gold_bar.xlsx'
# Use pandas.read_excel() function to open this file.
Skykomish_data = pd.read_excel(Skykomish_data_file)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/pandas/compat/_optional.py:158, in import_optional_dependency(name, extra, min_version, errors)
    157 try:
--> 158     module = importlib.import_module(name)
    159 except ImportError as err:

File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/importlib/__init__.py:126, in import_module(name, package)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1204, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1176, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1140, in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'openpyxl'

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
Cell In[3], line 2
      1 # Use pandas.read_excel() function to open this file.
----> 2 Skykomish_data = pd.read_excel(Skykomish_data_file)

File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/pandas/io/excel/_base.py:481, in read_excel(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend, engine_kwargs)
    479 if not isinstance(io, ExcelFile):
    480     should_close = True
--> 481     io = ExcelFile(
    482         io,
    483         storage_options=storage_options,
    484         engine=engine,
    485         engine_kwargs=engine_kwargs,
    486     )
    487 elif engine and engine != io.engine:
    488     raise ValueError(
    489         "Engine should not be specified when passing "
    490         "an ExcelFile - ExcelFile already has the engine set"
    491     )

File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/pandas/io/excel/_base.py:1621, in ExcelFile.__init__(self, path_or_buffer, engine, storage_options, engine_kwargs)
   1618 self.engine = engine
   1619 self.storage_options = storage_options
-> 1621 self._reader = self._engines[engine](
   1622     self._io,
   1623     storage_options=storage_options,
   1624     engine_kwargs=engine_kwargs,
   1625 )

File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/pandas/io/excel/_openpyxl.py:559, in OpenpyxlReader.__init__(self, filepath_or_buffer, storage_options, engine_kwargs)
    541 @doc(storage_options=_shared_docs["storage_options"])
    542 def __init__(
    543     self,
   (...)    546     engine_kwargs: dict | None = None,
    547 ) -> None:
    548     """
    549     Reader using openpyxl engine.
    550 
   (...)    557         Arbitrary keyword arguments passed to excel engine.
    558     """
--> 559     import_optional_dependency("openpyxl")
    560     super().__init__(
    561         filepath_or_buffer,
    562         storage_options=storage_options,
    563         engine_kwargs=engine_kwargs,
    564     )

File /opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/pandas/compat/_optional.py:161, in import_optional_dependency(name, extra, min_version, errors)
    159 except ImportError as err:
    160     if errors == "raise":
--> 161         raise ImportError(msg) from err
    162     return None
    164 # Handle submodules: if we have submodule, grab parent module from sys.modules

ImportError: `Import openpyxl` failed.  Use pip or conda to install the openpyxl package.
# Now we can see the dataset we loaded:
Skykomish_data
# Look at a single column, using the header name
Skykomish_data['water year']
# Plot data, specifying our x and y with column header names
plt.plot(Skykomish_data['water year'],Skykomish_data['peak value (cfs)'])

How to find help/documentation?#

help(np.mean)
np.mean?
help(pd.read_excel)
pd.read_excel?

Writing functions:#

def add_values(x,y):
    z = x + y
    return z
result = add_values(1,2)

print(result)

Import your custom functions:#

#def subtract_values(x,y):
#    z = x - y
#    return z
import my_functions
result = my_functions.subtract_values(10,5)

print(result)