5
我有一個帶有DateTimeIndex和每小時對象的列的Pandas Dataframe,我想將單個列轉換並輸出到由每小時值數組組成的JSON文件中。熊貓數據幀輸出到JSON
一個簡單的例子:
如果我有數據幀:
In [106]:
rng = pd.date_range('1/1/2011 01:00:00', periods=12, freq='H')
df = pd.DataFrame(randn(12, 1), index=rng, columns=['A'])
In [107]:
df
Out[107]:
A
2011-01-01 01:00:00 -0.067214
2011-01-01 02:00:00 0.820595
2011-01-01 03:00:00 0.442557
2011-01-01 04:00:00 -1.000434
2011-01-01 05:00:00 -0.760783
2011-01-01 06:00:00 -0.106619
2011-01-01 07:00:00 0.786618
2011-01-01 08:00:00 0.144663
2011-01-01 09:00:00 -1.455017
2011-01-01 10:00:00 0.865593
2011-01-01 11:00:00 1.289754
2011-01-01 12:00:00 0.601067
我想這個JSON文件:
[
[-0.0672138259,0.8205950583,0.4425568167,-1.0004337373,-0.7607833867,-0.1066187698,0.7866183048,0.1446634381,-1.4550165851,0.8655931982,1.2897541164,0.6010672247]
]
我的實際數據幀是多天的時間,因此將大致看像這樣:
[
[[email protected], [email protected]@hour24day1],
[[email protected], [email protected]@hour24day2],
[[email protected], [email protected]@hour24day3],
....
[[email protected], [email protected]@hour24LastDay]
]
非常優雅的解決方案。謝謝 – cmiller8 2013-03-18 19:07:42