Ask Question
20 January, 20:18

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)

+5
Answers (1)
  1. 20 January, 22:37
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers