Challenge 9 Megathread

For any and all questions relating to Challenge 9 :point_down: post away!

What’s the answer for the stretch questions?

1 Like

Hello everyone, I hope we are enjoying today’s challenge.

Kindly drop any questions here and discuss amongst yourselves without sharing answers.

What are the QUESTIONS? Neither the first two nor the “stretch” ones match up with the “answers”! All four questions ask “HOW MANY” which require integer answers likely > 3 so what is with the float “answers”?

The answers were just formatted funny.

The answers are written:

  1. ANSWER
  2. ANSWER

that’s not a decimal, It’s just denoting question 1, question 2.

1 Like

I’m using the df.head(#) function to pull all the rows in the wine.csv data set, but it’s only showing the first 5 rows and the last 5 rows, with a … in the middle of the table. How do I get the full data set to display?

First of, I’m not sure it a good idea to want to display an entire dataframe. You can pass in a value if to the .head() or .tail() method if you want to see more than the top 5 or bottom 5 rows. For example, if you are interesting in seeing that too 20 rows of a df named data, all you have to do is to run data.head(20).

If you are super interested in seeing every of your rows, just run data, and format your jupyter notebook to allow for displaying the whole dataframe, but this will slow your kernel should it be a very big dataset.

The .head() function is suppose to only show the first 5 rows. It’s for you to get familiar with how the data is setup without showing every row in the datasets (Imagine trying to print out 100k rows everytime you wanna check what your table looks like)

If you want the entire dataset, you can simply type in df and Jupyter notebooks will format it. However you may want to look at ways to sort the data without having to go throught he entire dataframe.

1 Like

I don’t seem to understand your point here. I will appreciate if you could clarify. Thanks!

You could simply format your answers as float, if you are sure that’s the problem.

It is perfectly okay. I will leave the message, it allows others to get same answer but with different perspectives.

Oh I was trying to answer the person above. I think they mistook the answers in the multiple choice to the question to be
“1.86, 2.59”, “1.86, 2.48”, “1.86, 2.71” and so on

Instead of
“Answer to 1: 86, Answer to 2: 59”, “Answer to 1: 86, Answer to 2: 48”, “Answer to 1: 86, Answer to 2:71”

They were asking why the answers were all smaller than 3, and not integer numbers. I just wanted to clarify.

1 Like

THANK YOU Mallowraiin! I didn’t think of that.

That’s a relief!

1 Like

Ahh, makes more sense now. I think this is super clear.

Thanks for the clarification!

1 Like

Hi kw1!

Kelvine95 and Mallowrain made some good points explaining that you probably don’t want to show the entire dataframe, and Kelvine95 gave one way you can show the entire dataframe, but here’s a method that was not mentioned:

Using The iloc Property

The iloc property could help you achieve your objective! More about it can be found here:
https://pandas.pydata.org/docs/reference/api/pandas.Series.iloc.html

It seems that with iloc, we can slice the dataframe. I did some testing and determined that the max rows the jupyter notebook is configured to show is 60, so this is what I did to show the entire dataframe:

print(df[0:60]["Magnesium"])
print(df[60:120]["Magnesium"])
print(df[120:180]["Magnesium"])

I only did this to see if it could be done, though. I’m not sure if looking at the entire data frame would be useful (even for testing), since the data frame could typically have many more rows in it than just a couple hundred.

In real-life data situations, you’ll never want to view the entire data. BUT if you really want to, then you can use the to_string() method and apply that to the DataFrame.

print(dataframe.to_string())
1 Like

Hi mods! (I’m guessing that’s @Kelvine95 and caroLHL?)

Two questions for yall:

  1. Can I post my answers for the stretch questions?
  2. When we have a question like this that only mods can answer, what’s the protocol? Should we just @mention you like I did in this post?

Thanks!!

2 Likes

Can someone please tell me how to delete cells? I accidentally added a cell above and below the one I was working in and I cant run my code. I tried Google, the video tutorial and other tutorials for Jupyter but the command they are telling me to use isn’t working. Super frustrating.

The cell I am trying to run code in has an asterisk in the square brackets - I have no idea what I hit on my keyboard to make this happen.

click on the left side of the cell and hit ‘D’ twice

2 Likes

An interesting thing about stretch questions.
you can combine two datasets indexes with operators when you pass them as arguments.

df[ A & B]

this will result in the intersection of A and B
image

1 Like