Sunday, 15 August 2010

data.frame - python pandas transform timeseries into multiple column DataFrame -



data.frame - python pandas transform timeseries into multiple column DataFrame -

i have timeseries of intraday day info looks below

ts =pd.series(np.random.randn(60),index=pd.date_range('1/1/2000',periods=60, freq='2h'))

i hoping transform info dataframe, columns each date, , rows time in date.

i have tried these,

key = lambda x:x.date() grouped = ts.groupby(key)

but how transform groups date columned dataframe? or there improve way?

import pandas pd import numpy np index = pd.date_range('1/1/2000', periods=60, freq='2h') ts = pd.series(np.random.randn(60), index = index) key = lambda x: x.time() groups = ts.groupby(key) print pd.dataframe({k:g k,g in groups}).resample('d').t

out:

2000-01-01 2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 \ 00:00:00 0.109959 -0.124291 -0.137365 0.054729 -1.305821 -1.928468 03:00:00 1.336467 0.874296 0.153490 -2.410259 0.906950 1.860385 06:00:00 -1.172638 -0.410272 -0.800962 0.568965 -0.270307 -2.046119 09:00:00 -0.707423 1.614732 0.779645 -0.571251 0.839890 0.435928 12:00:00 0.865577 -0.076702 -0.966020 0.589074 0.326276 -2.265566 15:00:00 1.845865 -1.421269 -0.141785 0.433011 -0.063286 0.129706 18:00:00 -0.054569 0.277901 0.383375 -0.546495 -0.644141 -0.207479 21:00:00 1.056536 0.031187 -1.667686 -0.270580 -0.678205 0.750386 2000-01-07 2000-01-08 00:00:00 -0.657398 -0.630487 03:00:00 2.205280 -0.371830 06:00:00 -0.073235 0.208831 09:00:00 1.720097 -0.312353 12:00:00 -0.774391 nan 15:00:00 0.607250 nan 18:00:00 1.379823 nan 21:00:00 0.959811 nan

python data.frame group pandas

No comments:

Post a Comment