I want to create a new column called "part_1_total" that pastes together all the values of the columns that contain the string 'Part 1' (same should be done for the next set of columns that contain 'Part 2' , Part 3' etc...)
Is there a quick way to do this?
My attempts:
# Attempt 1 yields 0 as it is to sum up numbers
def calc_total(df,string='Part 1'):
return df.loc[:,[x for x in df.columns if string in x]].sum(axis=1)
# Attempt number 2 pastes the column names into all the cells
asos['part_1_total'] = ''.join(asos.loc[:,[x for x in asos.columns if 'Part 1' in x]])