python - pandas minute data column to 60 minute columns -


i've seen related topics using transposition or pivot, can't make work. i've got data frame 2 columns, timestamp , minute-like data.

i want transpose data frame end 61 columns, follows;

old df looks like

    date                    value    0   2017-01-01 16:45        12   1   2017-01-01 16:46        22       ...                     ... n   2017-03-01 11:45        12 

i want new df be

    dayhour           ...   minute45   minute46   ...    0   2017-01-01 16     ...   12         22         ...     ...               ...   ...        ...        ... n   2017-03-01 11     ...   12         ...        ... 

i somehow managed via groupby , loop on 60 minutes, wonder if there more compact way of doing this.

you can create new columns dayhour , minute , pivot table.

df.assign(dayhour = df.date.dt.floor('h'), minute=df.date.dt.minute)\   .pivot(index='dayhour', columns='minute', values='value')\   .add_prefix('minute')  minute               minute45  minute46 dayhour                                 2017-01-01 16:00:00      12.0      22.0 2017-03-01 11:00:00      12.0       nan 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -