I have the following table:
TABLE_NAME jace building equipment
0 R338_1_FAHU2_SUPAIR_TEMP NaN NaN NaN
1 R1001_1_R1005_1_FAHU_1_CO2_SEN2 NaN NaN NaN
I wrote this sub-function that analyses one column and (should) return three.
def fill(tablename='R338_1_FAHU2_SUPAIR_TEMP'):
jace,building,equipment=re.findall('(^[RP].*?_[1-9])_*(.*?)_(F.*)',tablename)[0]
if not len(building):
building=re.findall('(.*)_',jace)[0]
return jace,building,equipment
this function returns for the first row
('R338_1', 'R338', 'FAHU2_SUPAIR_TEMP')
I want to insert those into jace,building, and equipment columns above I tried this:
df[['jace','building','equipment']]=df['TABLE_NAME'].apply(lambda x: (fill(x)))
it gave me
ValueError: Must have equal len keys and value when setting with an iterable
I also tried axis=1
inside apply()
, which seems to contradict with lambda for some reason
Any ideas how to make it work?
(I can use fill(x)[0], fill(x)[1]
, which should solve the issue, but that feels like hard-coding)