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)

Respuesta :

Answer:

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 " )

Explanation: