简体   繁体   English

API时间序列数据

[英]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 我有一些无法补充的数据,但是我正在向能源管理系统发出API请求,以建立一个简单的熊猫数据框架...当数据请求返回时,我对数据进行了pd_to.CSV写入,并且然后使用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? 如何将其合并到我的API请求中,将时间戳标记为“ Date”和parse_dates = True? (Skip the read/write data to CSV...) (将读/写数据跳过为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!!! 这是我希望对CSV进行读/写的地方,希望将其合并到API请求中...除非这是进行读/写的最佳实践?。.基本上,在下面的读/写步骤之间,作弊并打开Excel以标记时间戳记列“ Date”,我希望避免!

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. 您可以使用UtilityInfo.index.names=['Date']为索引命名。

You could also create a column from this index using df.reset_index() 您还可以使用df.reset_index()从此索引创建一列

Good ref : Rename Pandas DataFrame Index 良好的参考: 重命名Pandas DataFrame索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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