Export dataframe to csv

master
Dan Howe 7 years ago
parent 23789a8942
commit 4d19214d2e

@ -10,7 +10,8 @@ def pointdata(variables,
station=None, station=None,
lat=None, lat=None,
lon=None, lon=None,
units=True): units=True,
output=None):
"""Request point data from SILO. """Request point data from SILO.
Args: Args:
@ -113,7 +114,8 @@ def pointdata(variables,
base_url = 'https://siloapi.longpaddock.qld.gov.au/pointdata' base_url = 'https://siloapi.longpaddock.qld.gov.au/pointdata'
r = requests.get(base_url, params=params) r = requests.get(base_url, params=params)
text = r.content.decode() text = r.content.decode()
df = pd.read_csv(StringIO(text)) df = pd.read_csv(StringIO(text), parse_dates=['date'])
df = df.set_index('date')
# Add units to columns names # Add units to columns names
if units: if units:
@ -122,4 +124,8 @@ def pointdata(variables,
labels[key] = '{}_{}'.format(key, val) labels[key] = '{}_{}'.format(key, val)
df = df.rename(columns=labels) df = df.rename(columns=labels)
# Write to csv
if output:
df.to_csv(output)
return df return df

Loading…
Cancel
Save