sidsriv / Introduction-to-Data-Science-in-python

This repository contains Ipython notebooks of assignments and tutorials used in the course introduction to data science in python, part of Applied Data Science using Python Specialization from University of Michigan offered by Coursera
216 stars 437 forks source link

New to python, need help on Question 2 #2

Open LalehT opened 6 years ago

LalehT commented 6 years ago

Hi, could you please explain what does this piece of code do? why should we use Boolean masking? x = max(df['Gold'] - df['Gold.1']) ans = df[(df['Gold'] - df['Gold.1']) == x].index.tolist()

and why doesn't something like this work? ans = df[max(df['Gold']-df['Gold.1'])].index.tolist()

and what does this do? .index.tolist()

Thanks in advance.

Villan-98 commented 5 years ago

@LalehT max(df['Gold']-df['Gold.1']) gives the maximum difference between the value of df['Gold'] and df['Gold.1'] which is 3850(4809-959) ,this implies x=3850 . your code: '''df[max(df['Gold']-df['Gold.1'])]''' is equivalent to '''df[3850]''' which will give the key error.