I'm trying to create a function that removes the ' #1' from a column within a dataframe:
def formatSignalColumn(df):
for i,signal in enumerate(df['Signal list']):
df = df.set_value(i, 'Signal list', signal.replace(" #1", ""))
df = df.set_value(i, 'Signal list', signal.replace(" #2", ""))
return df
However, when I pass my DataFrame through this, it does not change anything.
tlog = formatSignalColumn(tlog)
Interestingly, when I run the for loop outside the function, it doesn't work either, but when I specifically choose the i
and signal
values it works...
i = 0
signal = tlog['Signal list'][i]
tlog= tlog.set_value(i, 'Signal list', signal.replace(" #1", ""))
tlog= tlog.set_value(i, 'Signal list', signal.replace(" #2", ""))
This doesn't make any sense to me. Anyone have any ideas?