Here is a sample of a dataset I have:
| ID | Project |
|---|---|
| 1 | 21st Townhouse 318 |
| 2 | The Residences 6 |
| 3 | Villanova Tower B |
| 4 | The Hills H |
| 5 | City Park |
I need to transform 'Project' column so that:
- if a row ends with numeric values, they should be dropped
- if a row ends with single letter, it should be dropped
- else, leave as it is
Here is how I want it to look like:
| ID | Project |
|---|---|
| 1 | 21st Townhouse |
| 2 | The Residences |
| 3 | Villanova Tower |
| 4 | The Hills |
| 5 | City Park |
I tried to search for some solution, and found this(for first condition with numeric values only):
df['Project']=df.Project[~((df.Project.astype(str).str.match("(.*\d)")) & (df.Project.astype(str).str.len() > 1))]
It worked, however, I tried to apply it for the second condition as well:
df['Project']=df.Project[~((df.Project.astype(str).str.match("(.*\w)")) & (df.Project.astype(str).str.len() == 1))]
But, It failed
Can you help me, please? Thank you!