I need to filter out strings from a df column, which can start with 1 digit or 2 digits and end with an alphabet. An example can 1A, 10A, 2B, 2C. I don't want strings such as 7B7 or 4B&. Then I need to extract the maximum digits from that string
I'm using the following code for extracting maximum:
if df.col.str[0].str.isdigit().all() and df.col.str.contains('[A-Z]').all()
and df.col.str[-1].str.isalpha().all():
print(df.col.str[:-1].astype(float).max())
ValueError: could not convert string to float: '4B&'
But somehow it's not working and I'm getting this value error.