I have a table where one column is the ID and the second is the unit number. I need group by ID to extract max floor or max stories in that ID and create an extra column max_floor so that all rows for that ID have the same value of max_floor.
Case 1: As per the unit number, it can start with 1 digit followed by letters or 2 digits followed by letters. In that case, extract digits and find the maximum number to get the floors, as shown in the table below:
Case 2: The unit number starts with 1 or 2 letters, followed by numbers. In that case, the number of unique values of those letters give us the maximum number of stories,as given in the table:
First I need to filter out these cases and then calculate the floors. Need help with both
Update: I'm trying filtering using regex for case 1. This is my code:
if re.search(r'^[0-9]{1,2}[A-Z]+$',df.number.fillna('').astype(str)):
print(df.number)```
But I'm getting the error:
```TypeError: expected string or bytes-like object```