Doubt with selecting rows from a dataframe

Hello! I’m doing the line charts bit of the Data analyst in python path and i have a doubt.
The questions requires us to select the first 12 rows from the dataframe unrate to make the line chart.
https://app.dataquest.io/m/142/line-charts/8/fixing-axis-ticks -this the code that i wrote and it worked. if link doesn’t work – (plt.plot(unrate[“DATE”].head(12), unrate[“VALUE”].head(12)))
However, the given solution selects the rows using - unrate[0:12]
From what i remember, we use that syntax to select columns, not rows, no? Isnt it supposed to be unrate.loc[0:11] for rows? Please help me out here.

Why don’t you try out their solution to see if it works or not? A lot of learning this kind of material is simply trying it out and seeing if it works or not. There’s usually more than 1 way to solve a problem. I tried an example problem online through a sample data set and doing df[0:5] gave me the rows.

I tried it and it worked. I went through the previous course again and realised that the shortcut df[row index] can be used to select rows (when using index numbers only). I mixed it up with with df.loc where you can use the shortcut df[column name(s)] to select columns but not rows.
Thank you for responding, though! Very much appreciated. :smile:

No problem and I’m glad you were able to figure it out!

1 Like