User-defined function to create a dataset
The problem is that the columns you have for the pd.DataFrame you fetch from the url are;
['time', 'latitude', 'longitude', 'depth', 'mag', 'magType', 'nst', 'gap', 'dmin', 'rms', 'net', 'id', 'updated', 'place', 'type', 'horizontalError', 'depthError', 'magError', 'magNst', 'status', 'locationSource', 'magSource']
Which does not match with the column names you inserted into the drop function. Reformat the column names [" magType "," nst"," gap"," dmin "," rms"," place "," type " ," horizontalError "," depthError "," magError "," magNst "," status "," locationSource "," magSource "," net","id"," updated "] in the drop function exactly matching with your pd.DataFrame object data.
PS: You might wanna look into fstrings or .format. That will make your code look a lot cleaner.
Second PS: You also might want to not recursively concatanate data. As data gets bigger, the process will be remarkable slower. The better way to do it is create a list (e.g. dfList) and append the list with the dataframes you fetch from the urls. And then use the function pd.concat(dfList). Cheers!
My task is to use a given user-defined function to create a dataset for a specific region.
I've insert my specific data in the function
But only got this error:
KeyError: "[' magType ' ' nst' ' gap' ' dmin ' ' rms' ' place ' ' type '\n ' horizontalError ' ' depthError ' ' magError ' ' magNst ' ' status '\n ' locationSource ' ' magSource ' ' net' 'id' ' updated '] not found in axis"
How do I solve this problem? Because when I look at my data I got all this information (magType etc.)