-1

I have a dataframe with a 'power' cars column of object type. I need to get the numeric values of ch. The data is like:

df = pd.DataFrame({'power': ['265 kW (360 ch)', '125 à 135 kW (170 à 184 ch)', '244 kW (332 ch) en 75D,']})

That's what I need:

df = pd.DataFrame({'power': [360, 184, 332]})

Can a power Regex person help me please? Or maybe with another technical expertise without being Regex?

Note: it's not just a question of how get a simple number in a string, please Mister Wiktor Stribizew, stoping mark people question as duplicated! Sorry if you have arrived to later to answer it! Thanks

1
  • Are these numbers of kW always 3 digits? Commented Apr 1, 2019 at 15:03

1 Answer 1

1

You can use df.apply with re.search:

>>> df.power.apply(lambda x: re.search(r'(\d+) ch', x).group(1))
0    360
1    184
2    332
Sign up to request clarification or add additional context in comments.

1 Comment

Yessss it works!!! Thanks brow :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.