Answer:
Check the explanation
Step-by-step explanation:
PYTHON CODE: (lesson.py)
import statistics
# function to find standard deviation, mean
def get_stats(csv_string):
# calling the function to clean the data
sample=clean(csv_string)
# finding deviation, mean
std_dev=statistics.stdev(sample)
mean=statistics.mean(sample)
# counting the element in sample
count=len(sample)
# return the results in a tuple
return (count, std_dev, mean)
# function to clean the csv string
def clean(csv_string):
# temporary list
t=[]
# splitting the string by comma
data=csv_string.split(',')
# looping item in data list
for item in data:
# removing space,single quote, double quote
item=item.strip()
item= item.replace("'",'')
item= item.replace('"','')
# if the item is valid
if item:
# converting into float
try:
t.append(float(item))
except:
continue
# returning the list of float
return t
if __name__=='__main__':
csv = "a, 1, '-2', 2.35, None,, 4, True"
print(clean(csv))
print(get_stats('1.0,2.0,3.0'))