Python functions can be saved into files and imported into IPython notebooks or used by Python scripts. It is very useful to create libraries of reusable code that can be tested, improved over time and shared.
Any file with a .py
extensions is a module and any function defined in that file can be imported.
Create a new file with your editor (Notepad++ on windows, Textwrangler on Mac) and paste the functions defined earlier,
do not copy %matplotlib inline
because it is notebook-specific.
Save the file as "analyze_mosquito_data_lib.py" in the same folder where you started the IPython notebook (~/swc
)
from analyze_mosquito_data_lib import analyze, fahr_to_celsius
%matplotlib inline
import pandas as pd
data = pd.read_csv('B2_mosquito_data.csv')
parameters = analyze(data)
print(parameters)
It is important to understand the workflow:
.py
filesIn the lession about version control we will see how to track improvements to our module