I'm working with a large set of csv(table) and I need to remove character-containing cells and keep the numeric cells.
For example.
p1 p2 p3 p4 p5
dcf23e 2322 acc41 4212 cdefd
So In this case, I only want to remove dcf23e, acc41 and cdefd. After removing those strings, I want to keep them as empty cells.
How would I do this? Thanks in advance.
The code that I've tried is this... , this code remove characters in a string but the problem is, if a string is 23cdgf2, it makes a string 232 which is not what I want. And after removing all the characters, when I try to convert strings to int for calculations, some of the strings became decimals since some string have 123def.24 -> 123.24
temp = ''.join([c for c in temp if c in '1234567890.']) # Strip all non-numeric characters
# Now converting strings to integers for calculations, Using function to use int() , because of the blank spaces cannot be converted to int
def mk_int(s):
s = s.strip()
return int(s) if s else 0
mk_int(temp)
print(temp)