-2

I have this table

Stars
3 stars
Stars 20
901stars
8

I'm using python to filter the table but I'm not sure of the regex to reject 8. [^0-9] will flag 3 stars, 901stars as errors too but I just want to flag that 8 is incorrect based on the regex.

The regex I need would only flag out the numbers (not number+string or string+number).

ekhumoro
  • 115,249
  • 20
  • 229
  • 336

2 Answers2

1

I'd suggest \d+$ to match 1 or more digits at the end of the line. (or even ^\d+$ to search from beginning of line).

disclaimer: I don't have a clue wrt Python, but if has a standard rx library, this should work.

MBaas
  • 7,248
  • 6
  • 44
  • 61
-1

Here is a way without using regex.

pd.to_numeric(df['Stars'],errors = 'coerce').isna()
rhug123
  • 7,893
  • 1
  • 9
  • 24