pythonpython-3.xcsvwriter

can I write to CSV form orderdict in python


what is the problem with my below code the error said that is not writeable

with open('F:\learning\coding\python learning\jadi excersisse\work with files\grades_for_exercise.csv') as f:
        myFile=csv.reader(f)
        person_mean=OrderedDict()
        for row in myFile:
            name=row[0]
            person_grades=[]
            for number in row[1:]:
                person_grades.append(int(number))
            person_mean[name]=mean(person_grades)
        print(list(person_mean.items()))
with open ('F:\learning\coding\python learning\jadi excersisse\work with files\one_result.csv') as csvfile:
        csvwriter=csv.writer(csvfile)
        csvwriter.writerows((person_mean))

i need the data be witten in csv file


Solution

  • By reading the document of open () function, I have found the problem. It is necessary to write the mode in open function. When I added the mode "w" for write in to the file, the problem was solved.