Trying to rename pandas dataframe column using regex, I know how to do it rename the list as per below but could not get success results with df.rename.
Input:
df.columns.values = ['Time', '101 <RoomTemperature> (C)', '102 <ChemberTemperature> (C)', '103 <U1100> (C)', '103 <U1200 (C)', '103 U1500> (C)']
Trials of the Renaming dataframe column as per below code using regex but it does not work. I could not think of how to put multiple instruction together in df.rename method.
df.rename(columns={c: c.strip() for c in df.columns.values.tolist()
if "<" and ">" in c:
re.search(r"(?<=<).*(?=>)",c).group(0)}, inplace=True)
I want it to follow regex and rename it to as per below:
df.columns.values = ["Time", "RoomTemperature", "ChemberTemperature", "U1100", "103 <U1200 (C)", "103 U1500> (C)"]