In [570]:
cd /root/git/SolarDataRESTfulAPI/


/root/git/SolarDataRESTfulAPI

In [1048]:
import os
print os.system("cd /root/git/SolarDataRESTfulAPI/ && git pull")
reload(IoTtoolkit)
reload(InfluxDBInterface)


0
Out[1048]:
<module 'InfluxDBInterface' from 'InfluxDBInterface.pyc'>

In [1049]:
import IoTtoolkit
import InfluxDBInterface
import time

In [1050]:
cat influxInterfaceCredentials2.json


[{"host":"livinglab2.powerprojects.se",
 "port":8086,
 "user":"uploader",
 "password":"ryKkSSnveKVpUMROt8kqvZCGJXJveu8MkJO",
 "database":"SolarLogdata"},
{"host":"livinglab2.powerprojects.se",
 "port":8086,
 "user":"uploader",
 "password":"ryKkSSnveKVpUMROt8kqvZCGJXJveu8MkJO",
 "database":"SolarProductionSites"},
{"host":"livinglab2.powerprojects.se",
 "port":8086,
 "user":"uploader",
 "password":"ryKkSSnveKVpUMROt8kqvZCGJXJveu8MkJO",
 "database":"SolarProductionAreas"},
{"host":"livinglab2.powerprojects.se",
 "port":8086,
 "user":"uploader",
 "password":"ryKkSSnveKVpUMROt8kqvZCGJXJveu8MkJO",
 "database":"test"}]



In [1051]:
DataLink = InfluxDBInterface.InfluxDBInterface("influxInterfaceCredentials2.json")

LogDB = DataLink.databases[u'SolarLogdata']
ProductionDB = DataLink.databases[u'SolarProductionSites']
AreaDB = DataLink.databases[u'SolarProductionAreas']
Test = DataLink.databases[u'test']

In [1026]:
q= "select Min(Energy) as Energy from e63710a4-78d9-4071-9a2e-ad35534355f4 group by time(1h) where time < '2014-11-24 23:59:00' and time > '2014-11-22' limit 1000"
res = ProductionDB.QueryDf(q,'s')
#ProductionDB.ResultToDataframe(res,'s')
res["Power"] = res["Energy"].diff().shift(-1)
res["Timestamp"] = res.index.to_series()
mydict = {"points":res.to_dict("list")}
mydict["columns"] = list(res.columns)
mydict


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1026-e9ca0ae27181> in <module>()
      2 res = ProductionDB.QueryDf(q,'s')
      3 #ProductionDB.ResultToDataframe(res,'s')
----> 4 res["Power"] = res["Energy"].diff().shift(-1)
      5 res["Timestamp"] = res.index.to_series()
      6 mydict = {"points":res.to_dict("list")}

TypeError: 'NoneType' object has no attribute '__getitem__'

In [1031]:
type(df) == pd.DataFrame


Out[1031]:
True

In [1036]:
type(None)


Out[1036]:
NoneType

In [927]:
SitesProduction = IoTtoolkit.Feed()

sites = ["46d55815-f927-459f-a8e2-8bbcd88008ee"]
    
PowerStreams = SitesProduction.CombineStreamsFromMulipleSources("Power",ProductionDB,sites,"Power",Compressed=False)
EnergyStreams = SitesProduction.CombineStreamsFromMulipleSources("Energy",ProductionDB,sites,"Energy",Compressed=True)
SitesProductionBuf = SitesProduction.GetBuffer()
SitesProductionBuf.Size = 5000

In [ ]:


In [928]:
t = time.time()-3600*36
a = SitesProductionBuf.Feed.GetValuesAt(t)
b = SitesProductionBuf.Feed.GetValuesAt(t+3600)
a,b


Out[928]:
(               Power0     Energy1
Timestamp  1416726000  1416726600
Value               0   188089117,
                Power0     Energy1
Timestamp  1416730200  1416730200
Value            4458   188091404)

In [929]:
rs = SitesProduction.GetResampleBuffer(t0,3600,10)

In [930]:
rs.AddResampleColumn("Power","Energy1",rs.InterpolatePowerFromCounter)
rs.AddResampleColumn("Energy","Energy1",rs.InterpolateCounter)

In [931]:
rs.Interpolate()


Out[931]:
Energy Power
1416736800 188102215 14973
1416740400 188117188 12560
1416744000 188129748 9892
1416747600 188139640 2657
1416751200 188142297 173
1416754800 188142470 0
1416758400 188142470 0
1416762000 188142470 0
1416765600 188142470 0
1416769200 188142470 0
1416772800 188142470 0

In [1042]:
df.plot()


---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
<ipython-input-1042-4f76bcc16520> in <module>()
----> 1 df.plot()

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, **kwds)
   2156                              secondary_y=secondary_y, **kwds)
   2157 
-> 2158     plot_obj.generate()
   2159     plot_obj.draw()
   2160     if subplots:

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
    899         self._args_adjust()
    900         self._compute_plot_data()
--> 901         self._setup_subplots()
    902         self._make_plot()
    903         self._add_table()

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
    948         else:
    949             if self.ax is None:
--> 950                 fig = self.plt.figure(figsize=self.figsize)
    951                 ax = fig.add_subplot(111)
    952                 ax = self._maybe_right_yaxis(ax)

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
    421                                         frameon=frameon,
    422                                         FigureClass=FigureClass,
--> 423                                         **kwargs)
    424 
    425         if figLabel:

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
     77     FigureClass = kwargs.pop('FigureClass', Figure)
     78     figure = FigureClass(*args, **kwargs)
---> 79     return new_figure_manager_given_figure(num, figure)
     80 
     81 

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
     85     """
     86     _focus = windowing.FocusManager()
---> 87     window = Tk.Tk()
     88     window.withdraw()
     89 

/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
   1765                 baseName = baseName + ext
   1766         interactive = 0
-> 1767         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   1768         if useTk:
   1769             self._loadtk()

TclError: no display name and no $DISPLAY environment variable

In [952]:
t0


Out[952]:
1416736800

In [828]:
def p(y):
    print y

In [829]:
a = [p,1,2]

In [830]:
a


Out[830]:
[<function __main__.p>, 1, 2]

In [831]:
a[0](1)


1

In [731]:
df.loc[t0,"Test2"]=2

In [851]:
df.iloc[:,1].diff().shift(-1).iloc[1:-1]


Out[851]:
1416740400    12560
1416744000     9892
1416747600     2657
1416751200      173
1416754800        0
1416758400        0
1416762000        0
1416765600        0
1416769200        0
Name: Energy1, dtype: object

In [845]:
tst.iloc[1:-1]


Out[845]:
1416740400    12560
1416744000     9892
1416747600     2657
1416751200      173
1416754800        0
1416758400        0
1416762000        0
1416765600        0
1416769200        0
Name: Energy1, dtype: object

In [825]:
rs.Data["Power"] = rs.Data["Energy1"].diff().shift(-1)

In [867]:
s1 = rs.ResampleValues["Energy1"]
s1


Out[867]:
1416736800    188102215
1416740400    188117188
1416744000    188129748
1416747600    188139640
1416751200    188142297
1416754800    188142470
1416758400    188142470
1416762000    188142470
1416765600    188142470
1416769200    188142470
1416772800    188142470
Name: Energy1, dtype: object

In [865]:
s2 = rs.ResampleTimes["Energy1"]
s2


Out[865]:
1416736800        0
1416740400        0
1416744000        0
1416747600        0
1416751200     1200
1416754800     3000
1416758400     6600
1416762000    10200
1416765600    13800
1416769200    17400
1416772800    21000
Name: Energy1, dtype: object

In [869]:
(s2 < 3600).replace(False,float("nan")) * s1


Out[869]:
1416736800    1.881022e+08
1416740400    1.881172e+08
1416744000    1.881297e+08
1416747600    1.881396e+08
1416751200    1.881423e+08
1416754800    1.881425e+08
1416758400             NaN
1416762000             NaN
1416765600             NaN
1416769200             NaN
1416772800             NaN
Name: Energy1, dtype: object

In [870]:
s2


Out[870]:
1416736800        0
1416740400        0
1416744000        0
1416747600        0
1416751200     1200
1416754800     3000
1416758400     6600
1416762000    10200
1416765600    13800
1416769200    17400
1416772800    21000
Name: Energy1, dtype: object

In [106]:
SitesProductionBuf.Data.index[0]


Out[106]:
1416480000

In [107]:
SitesProductionBuf.Data.loc[SitesProductionBuf.Data.index[0],"Energy1"] = 0

In [108]:
SitesProductionBuf.Data


Out[108]:
Power0 Energy1
time
1416480000 1561 0
1416480600 2211 188048286
1416481200 1476 188048537
1416481800 1145 188048728
1416482400 1250 188048935
1416483000 1857 188049243
1416483600 1959 188049571
1416484200 1921 188049891
1416484800 2297 188050271
1416485400 1636 188050558

In [109]:
for Value in SitesProductionBuf.Values:
    print Value


Power0
Energy1

In [110]:
SitesProductionBuf.Values


Out[110]:
Power0 Energy1
Timestamp 1416480000 1416480000
Value 1561 188047915

In [112]:
SitesProductionBuf.Values[Value].Timestamp


Out[112]:
1416480000.0

In [144]:
t0 = time.time()-3600*22
v0 = SitesProductionBuf.Feed.GetValuesAt(t0)
v0


Out[144]:
Power0 Energy1
Timestamp 1416750000 1416750000
Value 1323 188142297

In [116]:



Out[116]:
1416747381.664565

In [117]:
SitesProductionBuf.Feed.DataStreams.columns


Out[117]:
Index([u'Power0', u'Energy1'], dtype='object')

In [120]:
SitesProductionBuf.Data.columns


Out[120]:
Index([u'Power0', u'Energy1'], dtype='object')

In [121]:
pd


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-121-6068f4b5ff32> in <module>()
----> 1 pd

NameError: name 'pd' is not defined

In [122]:
import pandas as pd

In [123]:
df = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns)

In [125]:
df.loc[pd.MultiIndex,"Power0"] = 1


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-125-3bd2f43ded9b> in <module>()
----> 1 df.loc[pd.MultiIndex(1,2),"Power0"] = 1

/usr/local/lib/python2.7/dist-packages/pandas/core/index.pyc in __new__(cls, levels, labels, sortorder, names, copy, verify_integrity)
   2133         if levels is None or labels is None:
   2134             raise TypeError("Must pass both levels and labels")
-> 2135         if len(levels) != len(labels):
   2136             raise ValueError('Length of levels and labels must be the same.')
   2137         if len(levels) == 0:

TypeError: object of type 'int' has no len()

In [146]:
index = pd.MultiIndex.from_tuples([(1400,1280),(1400,1280),(1400,1290)], names=['ResampleTime', 'Timestamp'])

In [147]:
index


Out[147]:
MultiIndex(levels=[[1400], [1280, 1290]],
           labels=[[0, 0, 0], [0, 0, 1]],
           names=[u'ResampleTime', u'Timestamp'])

In [130]:
df.loc[index,"Power0"] = 1


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-130-2353b1845fd6> in <module>()
----> 1 df.loc[index,"Power0"] = 1

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
    113                     raise IndexingError('only tuples of length <= %d supported' %
    114                                         self.ndim)
--> 115                 indexer = self._convert_tuple(key, is_setter=True)
    116             else:
    117                 indexer = self._convert_to_indexer(key, is_setter=True)

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _convert_tuple(self, key, is_setter)
    147         else:
    148             for i, k in enumerate(key):
--> 149                 idx = self._convert_to_indexer(k, axis=i, is_setter=is_setter)
    150                 keyidx.append(idx)
    151         return tuple(keyidx)

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
   1066                     if isinstance(obj, tuple) and is_setter:
   1067                         return {'key': obj}
-> 1068                     raise KeyError('%s not in index' % objarr[mask])
   1069 
   1070                 return indexer

KeyError: '[(1300, 1280)] not in index'

In [135]:
df2 = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns,index=index)

In [940]:
import uuid

In [944]:
uuid.uuid1()


Out[944]:
UUID('139cf50a-7419-11e4-a510-f23c9173ce4a')

In [946]:
print time.time()
for f in range(1,50):
    print uuid.uuid1()
print time.time()


1416861219.96
2c9f6df8-7419-11e4-a510-f23c9173ce4a
2c9f7442-7419-11e4-a510-f23c9173ce4a
2c9f78ca-7419-11e4-a510-f23c9173ce4a
2c9f7cc6-7419-11e4-a510-f23c9173ce4a
2c9f8162-7419-11e4-a510-f23c9173ce4a
2c9f85cc-7419-11e4-a510-f23c9173ce4a
2c9f89a0-7419-11e4-a510-f23c9173ce4a
2c9f8d4c-7419-11e4-a510-f23c9173ce4a
2c9f91fc-7419-11e4-a510-f23c9173ce4a
2c9f95e4-7419-11e4-a510-f23c9173ce4a
2c9f9990-7419-11e4-a510-f23c9173ce4a
2c9f9d46-7419-11e4-a510-f23c9173ce4a
2c9fa610-7419-11e4-a510-f23c9173ce4a
2c9fad40-7419-11e4-a510-f23c9173ce4a
2c9fb10a-7419-11e4-a510-f23c9173ce4a
2c9fb4d4-7419-11e4-a510-f23c9173ce4a
2c9fb86c-7419-11e4-a510-f23c9173ce4a
2c9fbc0e-7419-11e4-a510-f23c9173ce4a
2c9fbfa6-7419-11e4-a510-f23c9173ce4a
2c9fc334-7419-11e4-a510-f23c9173ce4a
2c9fc6e0-7419-11e4-a510-f23c9173ce4a
2c9fca82-7419-11e4-a510-f23c9173ce4a
2c9fce38-7419-11e4-a510-f23c9173ce4a
2c9fd1e4-7419-11e4-a510-f23c9173ce4a
2c9fd5ae-7419-11e4-a510-f23c9173ce4a
2c9fd946-7419-11e4-a510-f23c9173ce4a
2c9fdce8-7419-11e4-a510-f23c9173ce4a
2c9fe08a-7419-11e4-a510-f23c9173ce4a
2c9fe42c-7419-11e4-a510-f23c9173ce4a
2c9fe7d8-7419-11e4-a510-f23c9173ce4a
2c9fec6a-7419-11e4-a510-f23c9173ce4a
2c9ff020-7419-11e4-a510-f23c9173ce4a
2c9ff3cc-7419-11e4-a510-f23c9173ce4a
2c9ff764-7419-11e4-a510-f23c9173ce4a
2c9ffb06-7419-11e4-a510-f23c9173ce4a
2c9ffeda-7419-11e4-a510-f23c9173ce4a
2ca0027c-7419-11e4-a510-f23c9173ce4a
2ca0063c-7419-11e4-a510-f23c9173ce4a
2ca00a06-7419-11e4-a510-f23c9173ce4a
2ca00db2-7419-11e4-a510-f23c9173ce4a
2ca01154-7419-11e4-a510-f23c9173ce4a
2ca014e2-7419-11e4-a510-f23c9173ce4a
2ca01884-7419-11e4-a510-f23c9173ce4a
2ca01c26-7419-11e4-a510-f23c9173ce4a
2ca01fd2-7419-11e4-a510-f23c9173ce4a
2ca02374-7419-11e4-a510-f23c9173ce4a
2ca02716-7419-11e4-a510-f23c9173ce4a
2ca02b1c-7419-11e4-a510-f23c9173ce4a
2ca02f5e-7419-11e4-a510-f23c9173ce4a
1416861219.97

In [142]:
df.append(df2)


Out[142]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 NaN NaN
1400 1280 NaN NaN

In [141]:
df


Out[141]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 NaN NaN

In [145]:
v0


Out[145]:
Power0 Energy1
Timestamp 1416750000 1416750000
Value 1323 188142297

In [149]:
v0.


Out[149]:
Power0 Energy1
Timestamp 1416750000 1416750000
Value 1323 188142297

In [150]:
df


Out[150]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 NaN NaN

In [154]:
df.index.append(pd.MultiIndex.from_arrays([[1,3]]))


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-154-7f3b7790326d> in <module>()
----> 1 df.index = df.index.append(pd.MultiIndex.from_arrays([[1,3]]))

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in __setattr__(self, name, value)
   1847         This allows simpler access to columns for interactive use."""
   1848         if name in self._internal_names_set:
-> 1849             object.__setattr__(self, name, value)
   1850         elif name in self._metadata:
   1851             return object.__setattr__(self, name, value)

/usr/local/lib/python2.7/dist-packages/pandas/lib.so in pandas.lib.AxisProperty.__set__ (pandas/lib.c:36628)()

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in _set_axis(self, axis, labels)
    398 
    399     def _set_axis(self, axis, labels):
--> 400         self._data.set_axis(axis, labels)
    401         self._clear_item_cache()
    402 

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in set_axis(self, axis, new_labels)
   1953         if new_len != old_len:
   1954             raise ValueError('Length mismatch: Expected axis has %d elements, '
-> 1955                              'new values have %d elements' % (old_len, new_len))
   1956 
   1957         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 1 elements, new values have 3 elements

In [155]:
df


Out[155]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 NaN NaN

In [165]:
df["Power0"]= 45

In [166]:
df["Power0"]


Out[166]:
ResampleTime  Timestamp
1300          1280         45
Name: Power0, dtype: int64

In [160]:


In [167]:
df


Out[167]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 45 NaN

In [174]:
df.iloc[0]


Out[174]:
Power0      45
Energy1    NaN
Name: (1300, 1280), dtype: object

In [175]:
SitesProductionBuf.Feed.DataStreams.


Out[175]:
Power0 Energy1
Database <InfluxDBInterface.InfluxDBlayer object at 0x7... <InfluxDBInterface.InfluxDBlayer object at 0x7...
Serie 46d55815-f927-459f-a8e2-8bbcd88008ee 46d55815-f927-459f-a8e2-8bbcd88008ee
Property Power Energy
Timeout None None
TOMarker None None
Type None None
Compressed False True

In [177]:
index


Out[177]:
MultiIndex(levels=[[1400], [1280, 1290]],
           labels=[[0, 0, 0], [0, 0, 1]],
           names=[u'ResampleTime', u'Timestamp'])

In [182]:
df2 = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns,index=index,data=[34,35])


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-182-5f82e109a31f> in <module>()
----> 1 df2 = pd.DataFrame(columns = SitesProductionBuf.Feed.DataStreams.columns,index=index,data=[34,35])

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __init__(self, data, index, columns, dtype, copy)
    250                 else:
    251                     mgr = self._init_ndarray(data, index, columns, dtype=dtype,
--> 252                                              copy=copy)
    253             else:
    254                 mgr = self._init_ndarray(data, index, columns, dtype=dtype,

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _init_ndarray(self, values, index, columns, dtype, copy)
    365             columns = _ensure_index(columns)
    366 
--> 367         return create_block_manager_from_blocks([values.T], [columns, index])
    368 
    369     @property

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in create_block_manager_from_blocks(blocks, axes)
   3183         blocks = [getattr(b, 'values', b) for b in blocks]
   3184         tot_items = sum(b.shape[0] for b in blocks)
-> 3185         construction_error(tot_items, blocks[0].shape[1:], axes, e)
   3186 
   3187 

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in construction_error(tot_items, block_shape, axes, e)
   3164         raise e
   3165     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 3166         passed,implied))
   3167 
   3168 

ValueError: Shape of passed values is (1, 2), indices imply (2, 3)

In [183]:
df2


Out[183]:
Power0 Energy1
ResampleTime Timestamp
1400 1280 34 34
1280 34 34
1290 34 34

In [180]:
df


Out[180]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 45 NaN

In [230]:
index = pd.MultiIndex.from_tuples([(1300,1280)],names=["ResampleTime","Timestamp"])

In [231]:
df3 = pd.DataFrame(index=index)

In [232]:
df3


Out[232]:
ResampleTime Timestamp
1300 1280

In [233]:
df3["C"]=0

In [234]:
df3


Out[234]:
C
ResampleTime Timestamp
1300 1280 0

In [227]:
df.join(df3)


Out[227]:
Power0 Energy1 A B C
ResampleTime Timestamp
1300 1280 45 NaN NaN NaN 0

In [228]:
df


Out[228]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 45 NaN

In [229]:
df3


Out[229]:
A B C
ResampleTime Timestamp
1300 1280 NaN NaN 0

In [235]:
df


Out[235]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 45 NaN

In [238]:
df["Power0"]=[(1300,1230,1),46]


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-238-47eb08ae1cc4> in <module>()
----> 1 df["Power0"]=[(1300,1230,1),46]

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __setitem__(self, key, value)
   1899         else:
   1900             # set column
-> 1901             self._set_item(key, value)
   1902 
   1903     def _setitem_slice(self, key, value):

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _set_item(self, key, value)
   1981         is_existing = key in self.columns
   1982         self._ensure_valid_index(value)
-> 1983         value = self._sanitize_column(key, value)
   1984         NDFrame._set_item(self, key, value)
   1985 

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _sanitize_column(self, key, value)
   2031         elif isinstance(value, Index) or _is_sequence(value):
   2032             if len(value) != len(self.index):
-> 2033                 raise ValueError('Length of values does not match length of '
   2034                                  'index')
   2035 

ValueError: Length of values does not match length of index

In [249]:
df.loc[(1300,1280),"Power0"]


Out[249]:
45

In [247]:
df.sortlevel(


Out[247]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 45 NaN

In [253]:
df["Power0"][(1300,1290)]= 0


---------------------------------------------------------------------------
IndexingError                             Traceback (most recent call last)
<ipython-input-253-73b7166599f5> in <module>()
----> 1 df["Power0"][(1300,1290)]= 0

/usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in __setitem__(self, key, value)
    615                         pass
    616 
--> 617             self.loc[key] = value
    618             return
    619 

/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
    112                 if len(key) > self.ndim:
    113                     raise IndexingError('only tuples of length <= %d supported' %
--> 114                                         self.ndim)
    115                 indexer = self._convert_tuple(key, is_setter=True)
    116             else:

IndexingError: only tuples of length <= 1 supported

In [257]:
ind2 = df.index.append(pd.MultiIndex.from_tuples([(1300,1280)]))

In [258]:
ind2


Out[258]:
MultiIndex(levels=[[1300], [1280]],
           labels=[[0, 0], [0, 0]],
           names=[u'ResampleTime', u'Timestamp'])

In [260]:
ind2.has_duplicates


Out[260]:
True

In [261]:
ind2.reindex()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-261-5499a48ebf1b> in <module>()
----> 1 ind2.reindex()

TypeError: reindex() takes at least 2 arguments (1 given)

In [263]:
ind2.insert(0,(1,2))


Out[263]:
MultiIndex(levels=[[1300, 1], [1280, 2]],
           labels=[[1, 0, 0], [1, 0, 0]],
           names=[u'ResampleTime', u'Timestamp'])

In [264]:
ind2


Out[264]:
MultiIndex(levels=[[1300], [1280]],
           labels=[[0, 0], [0, 0]],
           names=[u'ResampleTime', u'Timestamp'])

In [266]:
df0 = pd.DataFrame()

In [267]:
df0


Out[267]:

In [269]:
df


Out[269]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 0 NaN

In [270]:
df.sort_index()


Out[270]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 0 NaN

In [271]:
pd.version


Out[271]:
<module 'pandas.version' from '/usr/local/lib/python2.7/dist-packages/pandas/version.pyc'>

In [274]:
df["Power0"]=[(1300,1280),1]


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-274-8167ed7104e2> in <module>()
----> 1 df["Power0"]=[(1300,1280),1]

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __setitem__(self, key, value)
   1899         else:
   1900             # set column
-> 1901             self._set_item(key, value)
   1902 
   1903     def _setitem_slice(self, key, value):

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _set_item(self, key, value)
   1981         is_existing = key in self.columns
   1982         self._ensure_valid_index(value)
-> 1983         value = self._sanitize_column(key, value)
   1984         NDFrame._set_item(self, key, value)
   1985 

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _sanitize_column(self, key, value)
   2031         elif isinstance(value, Index) or _is_sequence(value):
   2032             if len(value) != len(self.index):
-> 2033                 raise ValueError('Length of values does not match length of '
   2034                                  'index')
   2035 

ValueError: Length of values does not match length of index

In [297]:
df.loc[(1300,1285),"Power0"]= 23

In [298]:
df


Out[298]:
Power0 Energy1 0
ResampleTime Timestamp
1300 1280 23 2 23

In [302]:
df.index.compress()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-302-fc7dd7b9e34a> in <module>()
----> 1 df.index.compress()

TypeError: Required argument 'condition' (pos 1) not found

In [302]:


In [303]:
df3


Out[303]:
C
ResampleTime Timestamp
1300 1280 0

In [306]:
df


Out[306]:
Power0 Energy1 0
ResampleTime Timestamp
1300 1280 23 2 23

In [307]:
df2


Out[307]:
Power0 Energy1
ResampleTime Timestamp
1400 1280 34 34
1280 34 34
1290 34 34

In [308]:
df.join(df2)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-308-d7d1976a74b7> in <module>()
----> 1 df.join(df2)

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in join(self, other, on, how, lsuffix, rsuffix, sort)
   3631         # For SparseDataFrame's benefit
   3632         return self._join_compat(other, on=on, how=how, lsuffix=lsuffix,
-> 3633                                  rsuffix=rsuffix, sort=sort)
   3634 
   3635     def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='',

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _join_compat(self, other, on, how, lsuffix, rsuffix, sort)
   3645             return merge(self, other, left_on=on, how=how,
   3646                          left_index=on is None, right_index=True,
-> 3647                          suffixes=(lsuffix, rsuffix), sort=sort)
   3648         else:
   3649             if on is not None:

/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.pyc in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy)
     37                          right_index=right_index, sort=sort, suffixes=suffixes,
     38                          copy=copy)
---> 39     return op.get_result()
     40 if __debug__:
     41     merge.__doc__ = _merge_doc % '\nleft : DataFrame'

/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.pyc in get_result(self)
    189 
    190         llabels, rlabels = items_overlap_with_suffix(ldata.items, lsuf,
--> 191                                                      rdata.items, rsuf)
    192 
    193         lindexers = {1: left_indexer} if left_indexer is not None else {}

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in items_overlap_with_suffix(left, lsuffix, right, rsuffix)
   3554         if not lsuffix and not rsuffix:
   3555             raise ValueError('columns overlap but no suffix specified: %s' %
-> 3556                              to_rename)
   3557 
   3558         def lrenamer(x):

ValueError: columns overlap but no suffix specified: Index([u'Power0', u'Energy1'], dtype='object')

In [407]:
dfa = pd.DataFrame(index=index,columns=["Power0","Energy1"],data=[[80,34]])

In [315]:
dfa


Out[315]:
Power0 Energy1
1280 80 34

In [316]:
df


Out[316]:
Power0 Energy1 0
ResampleTime Timestamp
1300 1280 23 2 23

In [329]:
df.loc[1500] = [1280,23,23,34]

In [358]:
df


Out[358]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2
1400 1280 23
1500 1200 1

In [374]:
df.drop(1280,axis=1,inplace = True)

In [355]:
df


Out[355]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2
1400 1280 23
1500 1200 1

In [356]:
dfa


Out[356]:
Power0 Energy1
1280 80 34

In [361]:
type(df.loc[1500])


Out[361]:
pandas.core.frame.DataFrame

In [362]:
dfa = df.loc[1500]

In [363]:
dfa]


Out[363]:
Power0 Energy1
Timestamp
1200 1

In [367]:
df.sort_index(inplace=True)

In [369]:
df


Out[369]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2
1400 1280 23
1500 1200 1

In [372]:
df.loc[1600,1280]=1

In [375]:
df


Out[375]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2
1400 1280 23
1500 1200 1
1600 NaN NaN

In [379]:
df.ix[1600,0] = 5

In [382]:
df.xs


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-382-d3e2ba24f400> in <module>()
----> 1 df.xs[0]

TypeError: 'instancemethod' object has no attribute '__getitem__'

In [384]:
index


Out[384]:
MultiIndex(levels=[[1300], [1280]],
           labels=[[0], [0]],
           names=[u'ResampleTime', u'Timestamp'])

In [386]:
df2


Out[386]:
Power0 Energy1
ResampleTime Timestamp
1400 1280 34 34
1280 34 34
1290 34 34

In [387]:



Out[387]:
MultiIndex(levels=[[1400], [1280, 1290]],
           labels=[[0, 0, 0], [0, 0, 1]],
           names=[u'ResampleTime', u'Timestamp'])

In [393]:
df.join(df3,how="outer")


Out[393]:
Power0 Energy1 C
ResampleTime Timestamp
1300 1280 23 2 0
1400 1280 23 NaN
1500 1200 1 NaN
1600 5 NaN NaN

In [394]:
df3


Out[394]:
C
ResampleTime Timestamp
1300 1280 0

In [391]:
df2


Out[391]:
Power0 Energy1
ResampleTime Timestamp
1400 1280 34 34
1280 34 34
1290 34 34

In [400]:
df.drop(1600,inplace=True)

In [401]:
df


Out[401]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2

In [403]:
df3


Out[403]:
C
ResampleTime Timestamp
1300 1280 0

In [404]:
df2


Out[404]:
Power0 Energy1
ResampleTime Timestamp
1400 1280 34 34
1280 34 34
1290 34 34

In [405]:
df


Out[405]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2

In [408]:
dfa


Out[408]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 80 34

In [414]:
dfa.loc[(1300,1280)]=float("nan")
dfa


Out[414]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 NaN NaN

In [418]:
df.join(dfa)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-418-d44c2e3fff48> in <module>()
----> 1 df.join(dfa)

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in join(self, other, on, how, lsuffix, rsuffix, sort)
   3631         # For SparseDataFrame's benefit
   3632         return self._join_compat(other, on=on, how=how, lsuffix=lsuffix,
-> 3633                                  rsuffix=rsuffix, sort=sort)
   3634 
   3635     def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='',

/usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _join_compat(self, other, on, how, lsuffix, rsuffix, sort)
   3645             return merge(self, other, left_on=on, how=how,
   3646                          left_index=on is None, right_index=True,
-> 3647                          suffixes=(lsuffix, rsuffix), sort=sort)
   3648         else:
   3649             if on is not None:

/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.pyc in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy)
     37                          right_index=right_index, sort=sort, suffixes=suffixes,
     38                          copy=copy)
---> 39     return op.get_result()
     40 if __debug__:
     41     merge.__doc__ = _merge_doc % '\nleft : DataFrame'

/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.pyc in get_result(self)
    189 
    190         llabels, rlabels = items_overlap_with_suffix(ldata.items, lsuf,
--> 191                                                      rdata.items, rsuf)
    192 
    193         lindexers = {1: left_indexer} if left_indexer is not None else {}

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in items_overlap_with_suffix(left, lsuffix, right, rsuffix)
   3554         if not lsuffix and not rsuffix:
   3555             raise ValueError('columns overlap but no suffix specified: %s' %
-> 3556                              to_rename)
   3557 
   3558         def lrenamer(x):

ValueError: columns overlap but no suffix specified: Index([u'Power0', u'Energy1'], dtype='object')

In [417]:



Out[417]:
Power0 Energy1
ResampleTime Timestamp
1300 1280 23 2

In [487]:
re = 1400
ts = 1390

In [488]:
Names = ["ResampleTime","Timestamp"]

In [489]:
index2 = pd.MultiIndex.from_tuples([(re,ts)],names = Names)

In [497]:
df2 = pd.DataFrame(index=index2)

In [498]:
Name="Energy"

In [500]:
df2[Name]=56

In [501]:
df2


Out[501]:
Energy
ResampleTime Timestamp
1400 1390 56

In [459]:
df.loc[1400,"1380"]=4

In [460]:
df


Out[460]:
Power Energy 1380
ResampleTime Timestamp
1400 1380 4 4 4

In [461]:
df.drop("1385",axis=1,inplace=True)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-461-7d01f83d5ac2> in <module>()
----> 1 df.drop("1385",axis=1,inplace=True)

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in drop(self, labels, axis, level, inplace, **kwargs)
   1462                 new_axis = axis.drop(labels, level=level)
   1463             else:
-> 1464                 new_axis = axis.drop(labels)
   1465             dropped = self.reindex(**{axis_name: new_axis})
   1466             try:

/usr/local/lib/python2.7/dist-packages/pandas/core/index.pyc in drop(self, labels)
   1808         mask = indexer == -1
   1809         if mask.any():
-> 1810             raise ValueError('labels %s not contained in axis' % labels[mask])
   1811         return self.delete(indexer)
   1812 

ValueError: labels ['1385'] not contained in axis

In [463]:
df


Out[463]:
Power Energy 1380
ResampleTime Timestamp
1400 1380 4 4 4

In [471]:
df = df.sort()

In [475]:
df


Out[475]:
Power Energy 1380 1385
ResampleTime Timestamp
1400 1380 0 0 0 0

In [492]:
index


Out[492]:
MultiIndex(levels=[[1400], [1380]],
           labels=[[0], [0]],
           names=[u'ResampleTime', u'Timestamp'])

In [493]:
index2


Out[493]:
MultiIndex(levels=[[1400], [1390]],
           labels=[[0], [0]],
           names=[u'ResampleTime', u'Timestamp'])

In [496]:
df.index = df.index.append(index2)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-496-ab656dee6675> in <module>()
----> 1 df.index = df.index.append(index2)

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in __setattr__(self, name, value)
   1847         This allows simpler access to columns for interactive use."""
   1848         if name in self._internal_names_set:
-> 1849             object.__setattr__(self, name, value)
   1850         elif name in self._metadata:
   1851             return object.__setattr__(self, name, value)

/usr/local/lib/python2.7/dist-packages/pandas/lib.so in pandas.lib.AxisProperty.__set__ (pandas/lib.c:36628)()

/usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in _set_axis(self, axis, labels)
    398 
    399     def _set_axis(self, axis, labels):
--> 400         self._data.set_axis(axis, labels)
    401         self._clear_item_cache()
    402 

/usr/local/lib/python2.7/dist-packages/pandas/core/internals.pyc in set_axis(self, axis, new_labels)
   1953         if new_len != old_len:
   1954             raise ValueError('Length mismatch: Expected axis has %d elements, '
-> 1955                              'new values have %d elements' % (old_len, new_len))
   1956 
   1957         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 1 elements, new values have 2 elements

In [495]:
df.index


Out[495]:
MultiIndex(levels=[[1400], [1380]],
           labels=[[0], [0]],
           names=[u'ResampleTime', u'Timestamp'])

In [501]:


In [502]:
df2


Out[502]:
Energy
ResampleTime Timestamp
1400 1390 56

In [505]:
df2.index


Out[505]:
MultiIndex(levels=[[1400], [1390]],
           labels=[[0], [0]],
           names=[u'ResampleTime', u'Timestamp'])

In [506]:
df


Out[506]:
Power Energy 1380 1385
ResampleTime Timestamp
1400 1380 5 56 0 0

In [507]:
df2


Out[507]:
Energy
ResampleTime Timestamp
1400 1390 56

In [515]:
pd.join(df,df2)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-515-374d2332c6d9> in <module>()
----> 1 pd.join(df,df2)

AttributeError: 'module' object has no attribute 'join'

In [513]:
df


Out[513]:
Power Energy 1380 1385
ResampleTime Timestamp
1400 1380 5 56 0 0

In [514]:
df2


Out[514]:
Energy
ResampleTime Timestamp
1400 1390 56

In [518]:
pd.merge(df,df2,left_index=True, right_index=True)


Out[518]:
Power Energy_x 1380 1385 Energy_y
ResampleTime Timestamp

In [520]:
pd.concat([df,df2,df])


Out[520]:
1385 1380 Energy Power
ResampleTime Timestamp
1400 1380 0 0 56 5
1390 NaN NaN 56 NaN
1380 0 0 56 5

In [529]:
dfx=pd.DataFrame(columns=)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-529-af26a667667f> in <module>()
----> 1 dfx=pd.DataFrame(columns=SitesProductionBuf.Feed.DataStreams.columns.append("Timestamp"))

/usr/local/lib/python2.7/dist-packages/pandas/core/index.pyc in append(self, other)
    756                      for x in to_concat]
    757 
--> 758         return Index(np.concatenate(to_concat), name=name)
    759 
    760     @staticmethod

ValueError: all the input arrays must have same number of dimensions

In [532]:



---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-532-fc9f684b9aff> in <module>()
----> 1 SitesProductionBuf.Feed.DataStreams.columns.append("t")

/usr/local/lib/python2.7/dist-packages/pandas/core/index.pyc in append(self, other)
    756                      for x in to_concat]
    757 
--> 758         return Index(np.concatenate(to_concat), name=name)
    759 
    760     @staticmethod

ValueError: all the input arrays must have same number of dimensions

In [528]:
dfx


Out[528]:
Power0 Energy1 Power (Power, 123)
0 NaN NaN 123 123
1 NaN NaN 34 34

In [533]:
dfx.index=dfx["Power0"]

In [534]:
dfx


Out[534]:
Power0 Energy1 Power (Power, 123)
Power0
NaN NaN NaN 123 123
NaN NaN NaN 34 34

In [537]:
dfx


Out[537]:
Power0 Energy1 Power (Power, 123)
Power0
NaN NaN NaN 123 123
NaN NaN NaN 34 34

In [538]:
SitesProductionBuf.Data


Out[538]:
Power0 Energy1
time
1416480000 1561 0
1416480600 2211 188048286
1416481200 1476 188048537
1416481800 1145 188048728
1416482400 1250 188048935
1416483000 1857 188049243
1416483600 1959 188049571
1416484200 1921 188049891
1416484800 2297 188050271
1416485400 1636 188050558

In [539]:
i2= pd.Series(name="time")

In [540]:
dfx= pd.DataFrame(index = i2)

In [554]:
dfx["test"]=1

In [560]:
dfx.loc[123,"test"]=55

In [561]:
dfx


Out[561]:
test (test, 123)
0 1 1
1 1 1
123 55 0

In [562]:
df3


Out[562]:
C
ResampleTime Timestamp
1300 1280 0

In [563]:
df2


Out[563]:
Energy
ResampleTime Timestamp
1400 1390 56

In [568]:
df2.loc[(1400,1380),"Energy"] = 4

In [569]:
df2


Out[569]:
Energy
ResampleTime Timestamp
1400 1390 4

In [1046]:
SitesProductionBuf.Data


Out[1046]:
Power0 Energy1

In [1047]:
ProdutionDB


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1047-eca2c6f557e3> in <module>()
----> 1 ProdutionDB

NameError: name 'ProdutionDB' is not defined

In [1052]:
____________________
********************
select Min(Energy) as Energy from 32383bde-7648-4abe-9dac-44701eabd72f group by time(1h) where time < '2014-11-30 22:59:00' and time > '2014-10-31 23:00:00' limit 1000
____________________


  File "<ipython-input-1052-c59a8ec43b5f>", line 2
    ********************
     ^
SyntaxError: invalid syntax

In [1053]:
ProdutionDB


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1053-eca2c6f557e3> in <module>()
----> 1 ProdutionDB

NameError: name 'ProdutionDB' is not defined

In [1055]:
d55=ProductionDB.QueryDf("select Min(Energy) as Energy from 32383bde-7648-4abe-9dac-44701eabd72f group by time(1h) where time < '2014-11-30 22:59:00' and time > '2014-10-31 23:00:00' limit 1000","m")

In [1056]:
d55.index.max()


Out[1056]:
1417089600000

In [1059]:
df.shape[0]


Out[1059]:
11

In [1063]:
df["Energy"].diff()/2


Out[1063]:
1416736800       NaN
1416740400    7486.5
1416744000      6280
1416747600      4946
1416751200    1328.5
1416754800      86.5
1416758400         0
1416762000         0
1416765600         0
1416769200         0
1416772800         0
Name: Energy, dtype: object

In [ ]: