I hope somebody can tell me how to conclude the following step :
I have the following dataframe:
df = [{'Failed by Fraud' : 3, 'Failed by Bot': 7, 'Failed by Geography':4, 'Failed by Suspicious Activity' : 2, 'Impressions': 22, 'Clicks':12, 'Date': '24/07/2016', "ID": 34},]
I unpivot it in Pandas with the following code:
pd.melt(df, id_vars=["Date", "Impressions", "Clicks", "ID"], var_name='Reason of Faiure', value_name='Failures')
The result is the following :
Date Impressions Clicks ID Reason of Faiure Failures
0 24/07/2016 22 12 34 Failed by Bot 7
1 24/07/2016 22 12 34 Failed by Fraud 3
2 24/07/2016 22 12 34 Failed by Geography 4
3 24/07/2016 22 12 34 Failed by Suspicious Activity 2
However, what I would like to have is the following result :
Date Impressions Clicks ID Reason of Faiure Failures
0 24/07/2016 22 12 34 NaN NaN
1 24/07/2016 NaN NaN 34 Fraud 3
2 24/07/2016 NaN NaN 34 Geography 4
3 24/07/2016 NaN NaN 34 Suspicious Activity 2
4 24/07/2016 NaN NaN 34 Bot 3
This means, in other words, adding 1 row which shows the impressions and clicks received for that day by ID, with empty values for Reasons of Failure and Failures. And on the other hand, empty values for Impressions and Clicks but with values for IDs, Reasons of Failures, and Failures