I have a dataframe df
,
import pandas as pd
df = pd.DataFrame(
{
"ID": [1, 2, 3, 4, 5],
"name": [
"Hello Kitty",
"Hello Puppy",
"It is an Helloexample",
"for stackoverflow",
"Hello World",
],
}
)
which looks like:
ID name
0 1 Hello Kitty
1 2 Hello Puppy
2 3 It is an Helloexample
3 4 for stackoverflow
4 5 Hello World
I have a list of strings To_remove_list
To_remove_lst = ["Hello", "for", "an", "It"]
I need to remove all the strings present in the list from the column name
of df
. How can I do this in pandas ?
My expected answer is:
ID name
0 1 Kitty
1 2 Puppy
2 3 is example
3 4 stackoverflow
4 5 World
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…