isds2020
isds2020 copied to clipboard
Question regarding exc 0.5.1
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:

Hi @Johan-Christensen, have you tried to reset the index of the final dataframe?
Hi! @jsr-p
I used this code to reset the index of the final dataframe:

However, I still get the same assertion error.
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 :)
That worked! Thank you