Reputation: 115
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
Upvotes: -1
Views: 2199
Reputation: 19
For float values, you'll want to make sure the regular expression considers both before and after the decimal point and change the datatype:
df['col'] = df['col'].str.extract('(\d+\.\d+)').astype(float)
Upvotes: 0
Reputation: 6564
You can clean the strings and leave only the digits. For example:
df['col'] = df['col'].str.extract('(\d+)').astype(int)
Upvotes: 3