abjer / isds2020

Introduction to Social Data Science 2020 - a summer school course abjer.github.io/isds2020
58 stars 92 forks source link

Question regarding 0.4.2 #10

Open danielarmel opened 3 years ago

danielarmel commented 3 years ago

Hi! I'm a little confused about exercise 0.4.2

We are supposed to rename the columns, but how do you only select the first four columns? I've tried iloc and loc, but that doesn't "change" the length of df_weather

jsr-p commented 3 years ago

hi @danielarmel , have you tried by first subsetting the dataframe like this?

iloc
danielarmel commented 3 years ago

I have, it changes it when I write the code:

image

But my problem is that it doesn't "save" these changes. When I try to rename them, I get this error:

image image

Which makes sense as the length of the list is still 8, while I try to rename only 4 columns.. I can't seem to figure out how to make the subset permanent

jsr-p commented 3 years ago

You will have to store the subsetted dataframe in a new variable before changing the column names :) As your code is now you only inspect the subsetted dataframe. In the following line where you try to change the column names you use the original dataframe which has 8 columns.

danielarmel commented 3 years ago

That fixed it, thanks!