python - Array of values in exact hour everyday(5 days) -


i have array, like:

                            0         1         2 date                                     2000-06-01 10:00:00  0.040457  0.326594  0.492136  2000-06-01 11:00:00  0.279323  0.877446  0.464523 2000-06-02 10:00:00  0.328068  0.837669  0.608559 2000-06-02 11:00:00  0.107959  0.678297  0.517435 2000-06-03 10:00:00  0.131555  0.418380  0.025725 2000-06-03 11:00:00  0.999961  0.619517  0.206108 2000-06-04 10:00:00  0.129270  0.024533  0.154769 2000-06-04 11:00:00  0.441010  0.741781  0.470402 2000-06-05 10:00:00  0.682101  0.375660  0.009916 2000-06-05 11:00:00  0.754488  0.352293  0.339337 

i need receive array of every values @ every hour of everyday. should dataframe as

10:00:00  [[0.040457, 0.040457, 0.492136], [0.328068, 0.837669, 0.608559], ..., [0.682101, 0.375660, 0.009916]] 11:00:00  [[0.279323, 0.877446, 0.464523], [0.107959, 0.678297, 0.517435], ..., [0.754488, 0.352293, 0.339337]] 

i tried one:

locs = a.index.indexer_at_time('11:00:00') a.iloc[locs] 

but doesn't show need. may there way via numpy? important: loops shouldn't used. if also, if possible

you can use pivot table creating column of 'hours'

df['hour'] = df.reset_index()['date'].dt.hour.values ndf = df.pivot_table(index=df.hour, columns=df.groupby(df['hour']).cumcount(),values=df[[0,1,2]]) 

output:

             0                                                1            \              0         1         2        3         4         0         1    hour                                                                         10    0.040457  0.328068  0.131555  0.12927  0.682101  0.326594  0.837669    11    0.279323  0.107959  0.999961  0.44101  0.754488  0.877446  0.678297                                                2                                \              2         3         4         0         1         2         3    hour                                                                          10    0.418380  0.024533  0.375660  0.492136  0.608559  0.025725  0.154769    11    0.619517  0.741781  0.352293  0.464523  0.517435  0.206108  0.470402                   4   hour             10    0.009916   11    0.339337   

you can use .loc speicfic hours data i.e

ndf.loc[10] 

output :

 0  0    0.040457    1    0.328068    2    0.131555    3    0.129270    4    0.682101 1  0    0.326594    1    0.837669    2    0.418380    3    0.024533    4    0.375660 2  0    0.492136    1    0.608559    2    0.025725    3    0.154769    4    0.009916 name: 10, dtype: float64 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -