import json
import pandas as pd
import numpy as np
rng = pd.date_range('1/1/2011 01:00:00', periods=12, freq='H')
df = pd.DataFrame(np.random.randn(12, 1), index=rng, columns=['A'])
print json.dumps(df.T.as_matrix().tolist(),indent=4)
of
[
[
-0.6916923670267555,
0.23075256008033393,
1.2390943452146521,
-0.9421708175530891,
-1.4622768586461448,
-0.3973987276444045,
-0.04983495806442656,
-1.9139530636627042,
1.9562147260518052,
-0.8296105620697014,
0.2888681009437529,
-2.3943000262784424
]
]
Or as a complete example with a few days using groupbyfunctionality:
rng = pd.date_range('1/1/2011 01:00:00', periods=48, freq='H')
df = pd.DataFrame(np.random.randn(48, 1), index=rng, columns=['A'])
grouped = df.groupby(lambda x: x.day)
data = [group['A'].values.tolist() for day, group in grouped]
print json.dumps(data, indent=4)
of
[
[
-0.8939584996681688,
...
-1.1332895023662326
],
[
-0.1514553673781838,
...
-1.8380494963443343
],
[
-1.8342085568898159
]
]
source
share