0

I have a question that is similar to this one: Pandas DataFrame: remove unwanted parts from strings in a column

The difference is that I want to remove all characters after a non digit character appear, for example:

    time    result
1   09:00   52m2 +6
2   10:00   62m2+balkon
3   11:00   57.+2 balkona
4   12:00   30 m2
5   13:00   46(43)

I need to trim this data to:

    time    result
1   09:00   52
2   10:00   62
3   11:00   57
4   12:00   30
5   13:00   46

I tried solutions from this, this and many more similar questions, but I couldn't find this specific use case.

Community
  • 1
  • 1
mrGreenBrown
  • 576
  • 1
  • 7
  • 20

1 Answers1

1

You can use extract:

df.result = df.result.str.extract('(\d+)', expand=False)
print (df)
    time result
1  09:00     52
2  10:00     62
3  11:00     57
4  12:00     30
5  13:00     46
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252