Yes, you can use a regular expression for this:

import re
output = re.sub(r'\d+', '', '123hello 456world')
print output  # 'hello world'
Answer from Martin Konecny on Stack Overflow
🌐
PyTutorial
pytutorial.com › python-remove-number-from-string-with-examples
PyTutorial | Python: Remove Number From String With Examples
August 4, 2023 - # define the string with numbers string_with_numbers = "hello 123 world" # create a translation table with all digits removed no_numbers_table = str.maketrans('', '', '0123456789') # use translate() to remove all digits from the string ...
🌐
Datasnips
datasnips.com › 155 › how-to-remove-numbers-from-text-using-python
Python | How to Remove Numbers from Text Using Python | Datasnips
1| import string 2| 3| text = '000This text33 has some numbers' 4| 5| mapping = str.maketrans('', '', string.digits) 6| text = text.translate(mapping) 7| 8| >> 'This text has some numbers' analyseup · Nlp | String | Translate · Did you find this snippet useful? Sign up for free to to add this to your code library · Sign Up For Free · Remove Stop Words from Text in DataFrame Column · Python · Pandas | Nltk | Nlp ·
🌐
Delft Stack
delftstack.com › home › howto › python › remove numbers from string python
How to Remove Numbers From String in Python | Delft Stack
February 2, 2024 - The below example code demonstrates how to use the string.join() method to remove the numbers from the string in Python.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string remove numbers
Python String Remove Numbers - Spark By {Examples}
May 21, 2024 - How to remove numbers from the string in Python? You can remove numeric digits/numbers from a given string in Python using many ways, for example, by
🌐
GeeksforGeeks
geeksforgeeks.org › python-ways-to-remove-numeric-digits-from-given-string
Python | Ways to remove numeric digits from given string - GeeksforGeeks
December 30, 2024 - For example we are given a string s=""abc123def456gh789" we need to extract all the numbers from the string so the output for the given string will become "123456789" In this article we will show different ways to extract digits from a string in Py · 2 min read Python Program for Remove leading zeros from a Number given as a string
Top answer
1 of 2
11

Try something like below:

import string
import re
import nltk
from nltk.tokenize import TweetTokenizer

tweet = "first think another Disney movie, might good, it's kids movie. watch it, can't help enjoy it. ages love movie. first saw movie 10 8 years later still love it! Danny Glover superb could play"

def clean_text(text):
    # remove numbers
    text_nonum = re.sub(r'\d+', '', text)
    # remove punctuations and convert characters to lower case
    text_nopunct = "".join([char.lower() for char in text_nonum if char not in string.punctuation]) 
    # substitute multiple whitespace with single whitespace
    # Also, removes leading and trailing whitespaces
    text_no_doublespace = re.sub('\s+', ' ', text_nopunct).strip()
    return text_no_doublespace

cleaned_tweet = clean_text(tweet)
tt = TweetTokenizer()
print(tt.tokenize(cleaned_tweet))

output:

['first', 'think', 'another', 'disney', 'movie', 'might', 'good', 'its', 'kids', 'movie', 'watch', 'it', 'cant', 'help', 'enjoy', 'it', 'ages', 'love', 'movie', 'first', 'saw', 'movie', 'years', 'later', 'still', 'love', 'it', 'danny', 'glover', 'superb', 'could', 'play']
2 of 2
0
# Function for removing Punctuation from Text and It gives total no.of punctuation removed also
# Input: Function takes Existing fie name and New file name as string i.e 'existingFileName.txt' and 'newFileName.txt'
# Return: It returns two things Punctuation Free File opened in read mode and a punctuation count variable.


from nltk.tokenize import word_tokenize
import string


def removePunctuation(tokenizeSampleText, newFileName):
    stringPun = list(string.punctuation)

    with open(tokenizeSampleText, "r") as existingFile:
        tokenize_existingFile = word_tokenize(existingFile.read())

    count_pun = 0
    words = []
    for word in tokenize_existingFile:
        if word in stringPun:
            count_pun += 1
        else:
            words.append(word)

    with open(newFileName, "w+") as puncRemovedFile:
        puncRemovedFile.write(" ".join(words))

    with open(newFileName, "r") as file:
        yield file.read(), count_pun


punRemoved, punCount = removePunctuation(
    "Macbeth.txt", "Macbeth-punctuationRemoved.txt"
)
print(f"Total Punctuation : {punCount}")
print(punRemoved)
🌐
YouTube
youtube.com › watch
How to Remove/Strip Numbers from a String in Python TUTORIAL (Common Python Interview Question) - YouTube
Python tutorial on how to remove numbers/integers/digits from a string.This is a common python interview question.Solution:'.join([i for i in x if not i.isdi...
Published   August 4, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-all-digits-from-a-list-of-strings
Python | Remove all digits from a list of strings - GeeksforGeeks
December 26, 2024 - This kind of application can come in many domains. Let's discuss certain ways to solve this problem. Method #1 : Using replace() + enumerate() + loop This is · 8 min read Python - Remove String from String List
Find elsewhere
🌐
Netlify
michael-fuchs-python.netlify.app › 2021 › 05 › 22 › nlp-text-pre-processing-i-text-cleaning
NLP - Text Pre-Processing I (Text Cleaning) - Michael Fuchs Python
def remove_punctuation_func(text): ''' Removes all punctuation from a string, if present Args: text (str): String to which the function is to be applied, string Returns: Clean string without punctuations ''' return re.sub(r'[^a-zA-Z0-9]', ' ', text) def remove_irr_char_func(text): ''' Removes all irrelevant characters (numbers and punctuation) from a string, if present Args: text (str): String to which the function is to be applied, string Returns: Clean string without irrelevant characters ''' return re.sub(r'[^a-zA-Z]', ' ', text)
🌐
MachineLearningMastery
machinelearningmastery.com › home › blog › how to clean text for machine learning with python
How to Clean Text for Machine Learning with Python - MachineLearningMastery.com
August 7, 2019 - We could just write some Python code to clean it up manually, and this is a good exercise for those simple problems that you encounter. Tools like regular expressions and splitting strings can get you a long way. Let’s load the text data so that we can work with it. The text is small and will load quickly and easily fit into memory. This will not always be the case and you may need to write code to memory map the file. Tools like NLTK (covered in the next section) will make working with large files much easier.
🌐
LinkedIn
linkedin.com › pulse › text-preprocessing-python-remove-numbers-mohd-faheem
Text Preprocessing in Python: Remove numbers
July 28, 2019 - Remove numbers if they are not relevant to your analyses. Usually, regular expressions are used to remove numbers.
🌐
Ekbana
blog.ekbana.com › pre-processing-text-in-python-ad13ea544dae
Pre-Processing Text in Python
October 31, 2018 - EKbana's blog spot for our latest works, our developer showcases and Office Culture. Ekbana.com.
🌐
NLTK
nltk.org › book › ch03.html
3 Processing Raw Text
Unicode supports over a million characters. Each character is assigned a number, called a code point. In Python, code points are written in the form \uXXXX, where XXXX is the number in 4-digit hexadecimal form. Within a program, we can manipulate Unicode strings just like normal strings.
🌐
Built In
builtin.com › software-engineering-perspectives › python-remove-character-from-string
How to Remove Characters From a String in Python | Built In
filter() will return an iterator containing all of the numbers in the string, and join() will join all of the elements in the iterator with an empty string. Ultimately, Python strings are immutable, so all of the mentioned methods will remove characters from the string and return a new string.
🌐
Replit
replit.com › home › discover › how to remove numbers from a string in python
How to remove numbers from a string in Python | Replit
April 13, 2026 - For truly international text, you'll need the unicodedata module when working with Unicode in Python. It provides a more powerful way to classify characters from any language. The unicodedata.category() function returns a character's official Unicode category. All numeric types—including decimal digits, letter-like numbers, and other numerals—belong to categories that start with 'N'. This makes checking .startswith('N') a reliable way to identify and remove any number. ... text = "Hello123World456" * 1000 # Large string import time start = time.time() result = ''.join(char for char in text if not char.isdigit()) end = time.time() print(f"Processed {len(text)} characters in {end - start:.6f} seconds")
🌐
Stack Overflow
stackoverflow.com › questions › 62465465 › how-do-i-use-nltk-to-extract-numbers-from-a-text-string-in-python
How do I use NLTK to extract numbers from a text string in Python - Stack Overflow
Copyimport nltk text = "Is there a one two three in there?" def existence_of_numeric_data(text): text=nltk.word_tokenize(text) pos = nltk.pos_tag(text) count = 0 for i in range(len(pos)): word , pos_tag = pos[i] if pos_tag == 'CD': return True return False print(existence_of_numeric_data(text)) is there a way to make this release the numbers in integer format? like for example · String says "Show my schedule for the next five days" it'll return the number "5" as a separate int · NLP Collective · python ·