user2696565
user2696565

Reputation: 629

pandas extract using multiple conditions

I have a data frame with a column that has numbers in format x.x or x.xx randomly embedded in a string. I can separately extract such numbers using

pd[colName].str.extract('(\d\.\d)') or
pd[colName].str.extract('(\d\d\.\d)') 

And then merging the two results. But how would I combines these two conditions together using some sort of 'or' condition to achieve the same in one go.

Upvotes: 1

Views: 625

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210832

Try this:

pd[colName].str.extract('(\d\.\d{1,2})')

Upvotes: 2

Related Questions