Closed AkselSB closed 3 years ago
Hi Aksel! You are using a lot of variable names, somewhere in your code this probably leads to the changes to the df not being assigned to the variable you intended. This is actually a good example of one of the benefits with the method-chaining approach :) /Matias
I've tried to chain the functions previously, but cannot figure out where the new functions would fit in when using this approach:
`def load_weather(year):
url = f"ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/by_year/{year}.csv.gz"
df_weather = pd.read_csv(url,
header=None) #the function uses pandas to read the csv.file
df_weather = df_weather.iloc[:,:4]
column_names = ['station', 'datetime', 'obs_type', 'obs_value']
df_weather.columns = column_names
df_weather['obs_value'] = df_weather['obs_value'] / 10
df_out = df_weather\
.loc[df_weather.obs_type == 'TMAX']\
.sort_values(by=['station', 'datetime'])\
.reset_index(drop=True)\
.copy()
return df_out
load_weather(1863)`
You don't necessarily need to use the method-chaining approach if you were able to now make it work, but if you are curious and want to try doing everything in one chain I would recommend reading up on the method ".assign()" https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.assign.html. With this you can create new variables/columns within the chain.
Hi, I'm having issues updating the annotated function in 2.1.1 with the functions processing "area" and "temporal data."
The following code runs with no errors, but the new functions are not included: `# INCLUDED IN ASSIGNMENT 1# YOUR CODE HERE import pandas as pd
importing the tool
def load_weather(year):
load_weather(1863)`