-2

enter image description here

I have a database that looks like the picture. I would like to remove all units of measurement. Some columns have writing on them is there any way I can do this?

3   390 kg/m3   1081 J/kgK  0.1 W/mK
4   420 kg/m3   1081 J/kgK  0.112 W/mK
5   600 kg/m3   1081 J/kgK  0.21 W/mK
6   2009.88 kg/m3   843.584 J/kgK   1.01233 W/mK
7   1674.2 kg/m3    933 J/kgK   0.685 W/mK
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Ideally you should clean up everything before loading the values into a Pandas DataFrame. But you failed to say where the data came from... If you are directly passed a full DataFrame, the workaround would be to edit the relevant columns to remove the unit string and then convert them to a numeric dtype. – Serge Ballesta Mar 07 '22 at 12:34

1 Answers1

3

You can clean the strings and leave only the digits. For example:

df['col'] =  df['col'].str.extract('(\d+)').astype(int)
gtomer
  • 5,643
  • 1
  • 10
  • 21