This is little convoluted, but I'll just show my data
I constructed following dataframe:
Mid_XYZ Mid_YYY Mid_ZZZ Select1 Select2
867 1019.11 1027.64 1022.68 XYZ YYY
873 1018.04 1027.58 1022.81 XYZ ZZZ
I would want to select values from columns based on Select1 and Select2 strings by matching on part of a column name. In a first row, this would be
1019.11 and 1027.64 (column Mid_XYZ and Mid_YYY) - because Select1 has string XYZ and Select2 has string YYY.
where, in a second row
1018.04 and 1022.81 (column Mid_XYZ and Mid_ZZZ)
Later, I plan to store sum of those values in new column. DataFrame will look like this
Mid_XYZ Mid_YYY Mid_ZZZ Select1 Select2 Sum
867 1019.11 1027.64 1022.68 XYZ YYY 2046.75
873 1018.04 1027.58 1022.81 XYZ ZZZ 2040.85
I can change column names to exact matching, but there should be some solution with regex? I know about df.filter(regex='XYZ'), but how can I do it row-wise?