简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM