简体   繁体   中英

API time series data

I have some data that cant be replecated but I am doing an API request to an energy management system to build a simple pandas data frame... When the data request comes back, I do a write to pd_to.CSV for the data, and then do a read_CSV with index_col='Date', parse_dates=True

How do I incorporate this to my API request labeling the time stamp as 'Date' and as well as the parse_dates=True? (Skip the read/write data to CSV...)

from pyhaystack.client.niagara import NiagaraHaystackSession
import pandas as pd


session = NiagaraHaystackSession(uri='http://192.x.x.x', username='username', password='password', pint=True)

op = session.nav()
op.wait()
nav = op.result
print(nav)

#Get Data for the OSA-T & convert to Pandas series:
oat = session.find_entity(filter_expr='outsideAir').result
oat_df = session.his_read_frame(oat, rng= '2017-10-01,2018-01-01').result
oat_df = pd.Series(oat_df[oat_df.columns[0]])


#Get Data for the electrical energy kWh & convert to Pandas series:
elecMeter = session.find_entity(filter_expr='elecMeter').result
elecMeter_df = session.his_read_frame(elecMeter, rng= '2017-10-01,2018-01-01').result
elecMeter_df = pd.Series(elecMeter_df[elecMeter_df.columns[0]])

#Get Data for the natural gas energy therms & convert to Pandas series:
gasMeter = session.find_entity(filter_expr='gasMeter').result
gasMeter_df = session.his_read_frame(gasMeter, rng= '2017-10-01,2018-01-01').result
gasMeter_df = pd.Series(gasMeter_df[gasMeter_df.columns[0]])

UtilityInfo = pd.DataFrame({'oat' : oat_df, 'kWh' : elecMeter_df, 'therms' : gasMeter_df})

This is where I am read/write to CSV that I am hoping to incorporate into the API request... Unless this is just best practices doing the read/write???.. Basically in between the read/write steps below I have to cheat and open up Excel to label the timestampt column 'Date' which I am hoping to avoid!!!

UtilityInfo.to_csv('C:\\Python Scripts\\UtilityInfo.csv', sep=',', header=True, index=True, na_rep='N/A')

UtilityInfo = pd.read_csv('C:\\Python Scripts\\UtilityInfo.csv', index_col='Date', parse_dates=True)

You can use UtilityInfo.index.names=['Date'] to give a name to the index.

You could also create a column from this index using df.reset_index()

Good ref : Rename Pandas DataFrame Index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM