2

I have the following pandas dataframe:

>>>ID      WKT
0 4272   Point(4.21189  3.1298)
1 2345   Point(None None)
2 1254   Point (3.8945 4.6712)
...

I would like to remove rows that do no contain any digits in the 'WKT' column, like row 1. I saw that ther are functions as isnumeric() but I don't want to check if all the characters in the cell are digits, but only if it contains digits or nit, and if not to remove it.

My desired output should look like this:

>>>ID      WKT
0 4272   Point(4.21189  3.1298)
2 1254   Point (3.8945 4.6712)
...
Reut
  • 1,555
  • 4
  • 23
  • 55

3 Answers3

5

You can use a str.contains method call on your WKT column

df[df['WKT'].str.contains('\d')]

     ID                     WKT
0  4272  Point(4.21189  3.1298)
2  1254   Point (3.8945 4.6712)

\d

\d matches a digit (equal to [0-9])

+ Quantifier — Matches between one and unlimited times, 
as many times as possible, giving back as needed (greedy)
halfer
  • 19,824
  • 17
  • 99
  • 186
Umar.H
  • 22,559
  • 7
  • 39
  • 74
2

You can use .str.contains with a filter, here \d+ will match more than one digit:

df = df[df['WKT'].str.contains(r'\d+')]
Wasif
  • 14,755
  • 3
  • 14
  • 34
1

Alternatively you can drop the data points containing "None" by

df[~df["WKT"].str.contains("None")]


    ID      WKT
0   4272    Point(4.21189 3.1298)
2   1254    Point(3.8945 4.6712)
Andre S.
  • 478
  • 4
  • 13