changes to the column values for machine learning

You can extract the leading digits with a regex:

df['engine'] = df['engine'].str.extract('(^\d+)')

output:

  engine
0   2150
1   2240
2   2150
3   2230
4   2050
5   2280

If you need integers:

df['engine'] = df['engine'].str.extract('(^\d+)').astype(int)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top