0

WHat better syntax can I use for the operation below? Column A has variables containing 2 different SI units with different conversion methods: in KB as well MB. So, I want to do the following actions on the column which is in a pandas dataframe: data = pd.dataframe({"sizes":[12mb, 7kb, 17kb, 11mn], "song-type":["karaoke", "rock", "jazz", "rap"]}, index = [1,2,3,4])

I want to extract the numerics from size and multiply each numeric component of the variables having 'mb' with 1000. Then have the results in int or float format

if 'M' in x:
    extract the numerics in x
    convert to float
    and assign x to (x * by 1000)
elif 'K' in x:
    extract the numerics in x and convert to float
    and assign it to x
else:
    extract the numerics in x and convert to float
    and assign it to x
  • 1
    provide minimal reproducible data and code – eshirvana Feb 02 '22 at 01:49
  • Does this answer your question? [if else function in pandas dataframe](https://stackoverflow.com/questions/43391591/if-else-function-in-pandas-dataframe) – Matthew Hays Feb 02 '22 at 01:51
  • Looks like a units conversion so https://stackoverflow.com/questions/39684548/convert-the-string-2-90k-to-2900-or-5-2m-to-5200000-in-pandas-dataframe might be helpful. – ALollz Feb 02 '22 at 02:53

0 Answers0