Ask Question
26 July, 13:11

1i) Standardize 'weight' column Write a function named standardize_weight that takes in as input a string and returns an integer. The function will do the following (in the order specified) : 1) convert all characters of the string into lowercase 2) strip the string of all leading and trailing whitespace 3) replace any occurences of 'lbs' with '' (remove it from the string) 4) replace any occurences of 'lb' with '' (remove it from the string)

+3
Answers (1)
  1. 26 July, 14:45
    0
    import numpy as np

    def standardize_weight (inp):

    #1

    inp=inp. lower ()

    print (inp)

    #2

    inp=inp. strip ()

    print (inp)

    #3

    inp=inp. replace ("lbs"," ")

    print (inp)

    #4

    inp=inp. replace ("lb"," ")

    print (inp)

    #5

    inp=inp. replace ("pounds"," ")

    print (inp)

    print (inp. find ("kg"))

    #6

    if (inp. find ("kg") >=0):

    inp=inp. replace ("kg"," ")

    print (inp)

    inp_int=int (inp)

    print (inp_int*2)

    inp=str (inp_int)

    print (inp)

    #7

    inp=inp. strip ()

    print (inp)

    #8

    if (inp. isdigit ()):

    inp=int (inp)

    #9

    else:

    inp=np. nan

    res=standardize_weight (" List albkg repLacleg sublkg ")
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “1i) Standardize 'weight' column Write a function named standardize_weight that takes in as input a string and returns an integer. The ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers