abjer / isds2020

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

Question regarding exc 0.5.1 #12

Open Johan-Christensen opened 3 years ago

Johan-Christensen commented 3 years ago

I have a question regarding 0.5.1. I have managed to code the function for loading the urls correctly, and created the variable list_of_dfs successfully. I have also (seemingly) managed to convert the list into a single dataframe named df_weather_period

However, I still get an assertion error when running the last line of code.

This is my code:

def load_weather_data(x): df_weatherdata = pd.read_csv(f'ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/by_year/186{x}.csv.gz', compression='gzip', header=None) df_weatherdata=df_weatherdata.iloc[:,:4] df_weatherdata.columns=['station','datetime','obs_type','obs_value'] return df_weatherdata

list_of_dfs=[load_weather_data(4),load_weather_data(5),load_weather_data(6),load_weather_data(7)] df_weather_period=pd.concat(list_of_dfs)

This is the assertion error I get: image

jsr-p commented 3 years ago

Hi @Johan-Christensen, have you tried to reset the index of the final dataframe?

Johan-Christensen commented 3 years ago

Hi! @jsr-p I used this code to reset the index of the final dataframe: image

However, I still get the same assertion error.

jsr-p commented 3 years ago

Either you will have to store the dataframe that you apply the reset_index() method on in the same variable to save the modified dataframe or you can use the (inplace=True) option in the method call :)

Johan-Christensen commented 3 years ago

That worked! Thank you