Tjeerd Tim
Tjeerd Tim

Reputation: 71

How to change text in specific column in panda data frame?

What code should I use to delete the text /wiki/ from the WIKIURL column in the Panda dataframe below? Im kind of stuck.

DataFrame:

    WIKIURL                     NUMBER
0   /wiki/blabla                9
1   /wiki/bladiebla             8
2   /wiki/blablabla             1
3   /wiki/kipapapap             2
4   /wiki/wqeqrwtyee            3
5   /wiki/soduyfhlas            1

Upvotes: 1

Views: 2412

Answers (1)

Anand S Kumar
Anand S Kumar

Reputation: 90929

You can use .str.replace() on the WIKIURL series. Example -

df['WIKIURL'] = df['WIKIURL'].str.replace('/wiki/','')

Demo -

In [95]: df
Out[95]:
            WIKIURL  NUMBER
0      /wiki/blabla       9
1   /wiki/bladiebla       8
2   /wiki/blablabla       1
3   /wiki/kipapapap       2
4  /wiki/wqeqrwtyee       3
5  /wiki/soduyfhlas       1

In [96]: df['WIKIURL'] = df['WIKIURL'].str.replace('/wiki/','')

In [97]: df
Out[97]:
      WIKIURL  NUMBER
0      blabla       9
1   bladiebla       8
2   blablabla       1
3   kipapapap       2
4  wqeqrwtyee       3
5  soduyfhlas       1

Upvotes: 3

Related Questions