Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Removing all non-numeric characters from string in Python

# Many right answers but in case you want it in a float, directly, without using regex:

x= '$123.45M'
float(''.join(c for c in x if (c.isdigit() or c =='.'))


#You can change the point for a comma depending on your needs.
#change for this if you know your number is an integer

x='$1123'    
int(''.join(c for c in x if c.isdigit())
Comment

PREVIOUS NEXT
Code Example
Python :: wait() in python tkinter 
Python :: install chromedriver ubuntu python 
Python :: get number of string python 
Python :: np zeros in more dimensions 
Python :: pandas from series to dataframe 
Python :: how to get the current url path in django template 
Python :: notify2 python example 
Python :: python histogram as a dictionary 
Python :: turn of warning iin python 
Python :: calcolatrice 
Python :: replace multiple spaces with single space python 
Python :: removing a channel from aconda 
Python :: python version command notebook 
Python :: rotational list python 
Python :: how to clean a mask cv2 in python 
Python :: download youtube audio python 
Python :: save pandas into csv 
Python :: plt change legend coordinates 
Python :: how to receive user input in python 
Python :: python how to set multiple conditional for single var 
Python :: delete index in df 
Python :: string pattern matching pandas 
Python :: except index out of range python 
Python :: set python3.7 as default ubuntu 
Python :: feet to meter python 
Python :: two input number sum in python 
Python :: python copy all files in a folder to nother folder 
Python :: pandas unnamed zero 
Python :: how to read a pkl file in python 
Python :: get n random numbers from x to y python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =