I have the following dataframe:
import pandas as pd
import re
df = pd.DataFrame({'Name': ['Paris', 'New York', '3 Pontas', '25466', '1', '4071'],
'Lat': [48.85, 40.73, -22.92, 22.85, 44.54, 55.87],
})
print(df)
Name Lat
Paris 48.85
New York 40.73
3 Pontas -22.92
25466 22.85
1 44.54
4071 55.87
I need to replace names that are formed by numbers only with empty space. I tried to implement the following code:
for i in range(0, len(df)):
contains_digit = len(re.findall('\d+', df['Name'].iloc[i]))
if(contains_digit > 0):
df['Name'].iloc[i] = ''
The output generated by my implementation is:
print(df)
Name Lat
Paris 48.85
New York 40.73
-22.92
22.85
44.54
55.87
However, I need to keep the names that have a number in the name as well. Thus, the desired output is:
Name Lat
Paris 48.85
New York 40.73
3 Pontas -22.92
22.85
44.54
55.87