isds2020 icon indicating copy to clipboard operation
isds2020 copied to clipboard

Question regarding exc 0.5.1

Open Johan-Christensen opened this issue 5 years ago • 4 comments
trafficstars

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

Johan-Christensen avatar Aug 02 '20 09:08 Johan-Christensen

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

jsr-p avatar Aug 02 '20 12:08 jsr-p

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

However, I still get the same assertion error.

Johan-Christensen avatar Aug 02 '20 13:08 Johan-Christensen

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 :)

jsr-p avatar Aug 02 '20 13:08 jsr-p

That worked! Thank you

Johan-Christensen avatar Aug 02 '20 14:08 Johan-Christensen