I have a df dataset with latitudes and longitudes columns like this.
station | long | lat |
---|---|---|
Station 1 | 50.80 | 60.80 |
Station 2 | 45 | 47 |
API: https://power.larc.nasa.gov/docs/tutorials/service-data-request/api/
This API provides some parameters (PS,WS10M_RANGE) for coordinate (latitute and longitute) points. I want to run this api code for all the latitute and longitute in my dataset. I already have a code for the json file, but I need to get the data in CSV format.
I then tried the following:
import os, json, requests
lat=df['lat'].values.tolist()
long=df['long'].values.tolist()
output = r"C:\Users\....."
base_url = r"https://power.larc.nasa.gov/api/temporal/monthly/point?parameters=PS,WS10M_RANGE&community=SB&longitude={longitude}&latitude={latitude}&format=CSV&start=2018&end=2021"
contents=[]
for latitude, longitude in zip(lat,long):
api_request_url = base_url.format(longitude=longitude, latitude=latitude)
response = requests.get(url=api_request_url, verify=True, timeout=30.00)
content=pd.read_csv(io.BytesIO(content), encoding='utf8', sep=",")
filename = response.headers['content-disposition'].split('filename=')[1]
filepath = os.path.join(output, filename)
with open(filepath, 'w') as file_object: