Google Colab source function in other Colab notebook

Viewed 2782

I have an ipynb on Google Colab my_functions.ipynb which consists of a simple function.

def get_mean(dat, col_nm):
  return dat[col_nm].mean()

From a different python notebook other_notebook.ipynb on Google Colab I'd like to source this function so that I could use it however I haven't been able to see a solution anywhere.

Appreciate any help on this.

Thanks,

Gareth

1 Answers

I saved my file with some useful functions as a .py file.

Then I store in Google Drive as 'functions.py'.

I then load my functions with the following call:

%run '/content/drive/My Drive/Colab Notebooks/functions.py'
Related