so i am struggling on understanding converting string to float in python.
i am using a csv file and i want each row of item to be a list, the food name to be a string, the carbs to be a string, and calories to be float
i don't understand how to do that i am trying this:
def menu_list(filep):
"""Function to read the csv file, create a nested list and return the list that is sorted based on calories in the ascending order."""
menulist = [] #store items
with open(filep) as csv_file: #read file
csv_reader = csv.reader (csv_file, delimiter=',')
next(csv_reader, None)
mlist = []
for row in csv_reader:
row = str
row[2] = float()
print (row)
menulist.sort(key=lambda x: x[1])
return menulist
every time i run this it give me the error : 'type' object does not support item assignment
can someone help me fix my code and convert string to float?