The orginal dataset has columns like: Time A_1 A_2 B_1 B_2 C_1 and all the columns except 'Time' have numeric values. Need the codes that can automatically add new columns: in this case, A_All B_All C_All and A_All = A_1 + A_2
B_All = B_1 + B_2
C_All = C_1 The problem is that, the column names of the original dataset, instead of 'A_:' 'B_:' 'C_:', can be anything (e.g. 'Apple_:', 'Test_:' etc.; the new columns would accordingly have names like 'Apple_All', 'Test_All'). In addition, there could be any number of 'A_:' columns: e.g. 'A_1-A_7' Hard coding like: A_All = sum(of A_1-A_2); wouldn't work therefore. I'm expecting codes that achieve the following objectives: 1. Read column names from the original dataset - have;
2.1 for columns whose names have a format like 'alphabetic characters + underscore + numbers': e.g. Type_3
2.2 identify how many columns there are whose names have the same alphabetic characters: e.g. 'Type'
3. create new columns whose names are 'same alphabetic characters + underscore + "All"': e.g. Type_All
4. the value for the new column is therefore: e.g. sum(of Type_1-Type_&NumColType). To make the question easier, the numeric part of the column names always starts from '1', and increases by 1. e.g. for 'Type_:' columns, it would be Type_1 Type_2 Type_3.
... View more