A basic question for Guided Project: Visualizing Earnings Based On College Majors

Why the two snippets of code below generate different plots? Shouldn’t they both return the last 10 rows of dataframe?
recent_grads.loc[-10:].plot.bar(x = 'Major', y = 'ShareWomen')

recent_grads[-10:].plot.bar(x = 'Major', y = 'ShareWomen')

The first plot you’re plotting all values because the “loc” (label-based), and the second plot only the last 10 items, you can use the “iloc” (integer-based)

recent_grads.iloc[-10:].plot.bar(x = ‘Major’, y = ‘ShareWomen’)

1 Like