Line chartr-matplotlib

The line chart i did is different from the answer. Why did it happen?

Screen Link: https://app.dataquest.io/m/142/line-charts/7/adding-data

My Code:

unrate12=unrate.loc[0:12,:]
plt.plot(unrate12['DATE'],unrate12['VALUE'])
plt.show()

You are doing great!

You just happen to plot the value more by 1. It should be unrate12=unrate.loc[0:11,:]

The answer shows unrated12=unrated12[0:12]

Now i get a little bit confused bewlow.

df[0:12]
df.loc[0:12]

Hey @candiceliu93

To answer your question -

df[0:12] is a shorthand convention of df.iloc[0:12]. This will slice the rows from our dataframe(unrated12) based on integer positions.

df.loc[0:12] is primarily label based, it can access a group of rows and columns by label(s) or a boolean array.

I believe your confusion is clear now. Just in case, if you want to refresh/ brush up your skills on df.loc & df.iloc, i suggest you to quickly go through our courses:

Introduction to Pandas
Exploring data with Pandas - Intermediate

Best
Kalyan

Got it now! After review the previous course, I think it help me to memories it firmly.

Thank you!!

1 Like

Awesome :blush:

Cheers
K!