python - Pandas dataframe: how to create columns from values? -
i have pandas dataframe looks like:
day payment_method actuals 0 2015-03-31 dcash_t3m 32 1 2015-03-31 dcash_t3m_3d 90 2 2015-03-31 paypal 34 4 2015-04-01 dcash_t3m 16 5 2015-04-01 dcash_t3m_3d 54 6 2015-04-01 paypal 33 7 2015-04-02 dcash_t3m 7 8 2015-04-02 dcash_t3m_3d 80 9 2015-04-02 paypal 38
what want perform time series analysis on them. advantageous if had column each payment method reporting corresponding actuals , order total values , times series.
day dcash_t3m dcash_t3m_3d paypal 2015-03-31 32 90 34 2015-04-01 16 54 33 2015-04-02 7 80 38
datatime object new column distinct date each roe. values of column payment_method 3 new columns each of them containing values in actuals.
you want pivot
:
in [27]: df.pivot(index='day', columns = 'payment_method', values = 'actuals') out[27]: payment_method dcash_t3m dcash_t3m_3d paypal day 2015-03-31 32 90 34 2015-04-01 16 54 33 2015-04-02 7 80 38
Comments
Post a Comment