5
I have a dataframe in the following template:
lista = []
lista.append(['A1','2','A3'])
lista.append(['4','A5','6'])
lista.append(['A7','8','9'])
df = pd.DataFrame(lista, columns=['A', 'B', 'C'])
What I want is to remove the character 'To' of all columns. I know I can get it out by going column by column with the command (df. Series):
df.A.replace('A', '', regex = True)
df.B.replace('A', '', regex = True)
df.C.replace('A', '', regex = True)
Upshot:
However, I would like to set up a function that goes through my dataframe removing this specific character.
I tried to perform an iteration on the columns and pick each one up as follows:
for column in df.columns[1:]:
print(column)
df[column] = df.column.replace('A', '', regex = True)
But the following error returns to me:
Attributeerror: 'Dataframe' Object has no attribute 'column'
Any idea?
I wasn’t aware of the possibility of not using the command replace directly. It worked very well, thank you very much!
– Clayton Tosatti