Make sure that kilogram are converted to grams pandas

I have the following series

s = pd.Series({0: '1kg',
 1: '500g',
 2: '200g'})

What I want to do is to make a very similar column that basically has the same type of measurement, that being in grams. So in this case convert the 1kg to one thousand int value and leave the gram integer in the normal state. Note: The value can alter on the kg part. Any ideas on how I could do this?

Wanted result


>Solution :

The module quantiphy handles this type of use case:

import pandas as pd 
from quantiphy import Quantity

s = pd.Series({0: '1kg',
 1: '500g',
 2: '200g'})



0    1000.0
1     500.0
2     200.0
dtype: float64

Leave a Reply