What are these two functions doing?

Hey guys, currently working through 06_multicat and I’ve ran into code that I can’t seem to understand no matter how hard I try.

Here is the code:

def get_x(r): return r['fname']
def get_y(r): return r['labels']
dblock = DataBlock(get_x = get_x,
                  get_y = get_y)

Basically, what is the parameter “r” doing? I understand that it’s returning all of the data under ‘fname’, but how is it doing so? What’s causing it to iterate? Why does it not also pass the value ‘fname’ into get_x?

Thanks in advance guys.

Hi Robert

My guess that r is “dictionary like” so r[‘fname’] returns the value associated when using the key ‘fname’ which I guess the the file name /a/b/bigcat.jpg and the ‘label’ is cat.

Pandas has a similar facility.

Regards Conwyn

Hi Robert

OK it is on page 220.
df = pd.read_csv(path/‘train.csv’)
This creates a three column panda collection filename (fname) label (chair/car/horse person) and is_valiid.

Pandas allows access by key or by row.

Regards Conwyn

Ah yes, so it’s a pandas thing. I had a feeling it was so, good thing that I recently started a course on pandas. Thanks for the answer.