I have the following dataframe:-
import pandas as pd
df = pd.read_csv('filename.csv')
print(df)
date organic paid source_type
4/1/2018 39911909.19 38575924.75 Search
4/1/2018 5085939.952 882.608927 Social
4/1/2018 16227439.73 0 Mail
4/1/2018 0 5671871.24 Display Ads
4/1/2018 91215520.23 0 Direct
4/1/2018 15743479.56 0 Referrals
I want to add a column total_sum for all the source types except when source type is "Search". If the source_type is search I want to break down the single row into two and source type becomes organic search and paid search. Inshort a df like below. The summing part is easy to handle i am just stuck with the breaking of rows and conditional column prefix part. Dataframe I need:-
date source_type Total Sum
4/1/2018 Organic Search 39911909.19
4/1/2018 Paid Search 38575924.75
4/1/2018 Social 5086822.561
4/1/2018 Mail 16227439.73
4/1/2018 Display Ads 5671871.24
4/1/2018 Direct 91215520.23
4/1/2018 Referrals 15743479.56