Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

Using Python to try and pull forecast dew point data for a single location, with the goal being to come up with code that can pull the forecasted dew points and write it into a csv file. My question is to see if there's a way to print only the data within the array without showing the coordinates and other items.

Computer is a Windows running Python 3.6 via Anaconda. I've been able to focus in on just a few forecast data points I'm looking for (shown as [12:15] in the code) but no matter what it produces the coordinates and other data that I don't exactly need. I tried messing around with xarray.DataArray.drop a bit but I couldn't figure out exactly what I would need to drop.

import csv

import matplotlib.pyplot as plt

import pandas as pd

import xarray as xr

import datetime as dt

from datetime import datetime, timedelta

dayFile = - timedelta(days=1)

dayFile  = dayFile.strftime("%Y%m%d")

url='' %(dayFile)

ds = xr.open_dataset(url)

lati = 41.4; loni = 100.8

dsloc = ds.sel(lon=loni, lat=lati, method='nearest')

data_to_write_day_0 = dsloc['dpt2m'][12:15]


Edit: Expected output would be producing the forecast numbers only (I.e. 283.729, 284.827, 283.282). I guess in other words the desire is to break up the array so that only the forecasted values are printed out.

1 Answer

0 votes
by (41.4k points)

Here, for accessing the data we will use the values attribute.

 Values returns the data as a numpy.ndarray:

for x in data_to_write_day_0.values: print(x)





Browse Categories