I have the following pandas dataframe:
import pandas as pd
import numpy as np
np.random.seed(0)
daytime = pd.date_range('2015-02-24', periods=6, freq='d')
df = pd.DataFrame({'DATE': ['2015-02-24', '2015-02-24', '2015-02-25', '2015-02-25', '2015-02-26', '2015-02-26'],
'HappyCustomer': ['True', 'False','True', 'False','True', 'False'],
'HappyCustomerCount': [2, 4,1, 6, 2, 3] })
df.set_index('DATE', inplace=True)
df.head(6)
HappyCustomer HappyCustomerCount
DATE
2015-02-24 True 2
2015-02-24 False 4
2015-02-25 True 1
2015-02-25 False 6
2015-02-26 True 2
2015-02-26 False 3
I think the column HappyCustomer is redundant, since it is always 'True' and 'False'. I would like to transform the column to sth. like this:
Solution:
HappyCustomerCount_True HappyCustomerCount_False
DATE
2015-02-24 2 4
2015-02-25 1 6
2015-02-26 2 3
Optional:
In best case scenario I can do this transformation with (SQL related) functions like groupby since I have to do the same job later in SQL database.
How can I do this?