How to remove numbers from string terms in a pandas dataframe

前端 未结 4 1073
离开以前
离开以前 2020-12-04 15:42

I have a data frame similar to the one below:

Name    Volume  Value
May21   23      21321
James   12      12311
Adi22   11      4435
Hello   34      32454
Gi         


        
4条回答
  •  盖世英雄少女心
    2020-12-04 16:02

    Although the question sounds more general, the example input only contains trailing numbers. In this case you don't have to use regular expressions, since .rstrip (also available via the .str accessor of Series objects) can do exactly this:

    import string
    df['Name'] = df['Name'].str.rstrip(string.digits)
    

    Similarly, you can use .lstrip to strip any digits from the start, or .strip to remove any digits from the start and the end of each string.

提交回复
热议问题