How to run an existing function from Jupyter notebook

Try the load magic;

%load f.py

That automatically loads the in the entire contents of file so that you can edit it in a cell.

from f import f

Is another option.

If neither one of those work for you could try adding your notebook's directory to the the system path by running this block as a cell before trying to call your function;

import os
import sys
nb_dir = os.path.split(os.getcwd())[0]
if nb_dir not in sys.path:
    sys.path.append(nb_dir)

%run f.py

load magic was just copying the whole file into a cell, which was not what i need. Neither did the importing worked for me. was throwing some weird errors. So i ended up using the run magic.