Doubt beginner! Manipulating series

1

I'm doing my first analysis with Pandas in Python 3. I'm practicing with a game of thrones dataset that contains the killings in the books.

One of the columns in the dataframe refers to the house and in this column there are repeated values of the type: Stark / Stark House.

I would like to know how to remove the word "home" from the above column.

Can anyone please help me?

    
asked by anonymous 06.05.2018 / 14:58

1 answer

1

You can use the replace function:

str = "Casa Stark"
str = str.replace("Casa ", "")
print(str) #Retorna Stark

You'll have to use it inside a loop, you can do something like this:

array = [
  ["coluna 1", "coluna 2", "X"],
  ["coluna 1", "coluna 2", "Stark"],
  ["coluna 1", "coluna 2", "Casa Stark"],
  ["coluna 1", "coluna 2", "Casa Z"],
  ["coluna 1", "coluna 2", "Casa Stark"],
]

for elemento in array:
  elemento[2] = elemento[2].replace("Casa ", "")
  print(elemento[2])
    
06.05.2018 / 15:20