fork download
  1. import csv
  2. path = "sample1.csv"
  3. f = open(path,"r",encoding="utf_8")
  4. reader = csv.reader(f)
  5. header = next(f)
  6. #print(header)
  7. dictK = {}
  8. dictS = {}
  9. dictSK = {}
  10. for row in reader:
  11. key = row[2] + '|' + row[1]
  12. if key not in dictSK:
  13. dictSK[key] = 0
  14. dictSK[key] += 1
  15. dictK[row[1]] = True
  16. dictS[row[2]] = True
  17. f.close
  18.  
  19. path = "sample2.csv"
  20. f = open(path,"w",encoding="utf_8",newline='')
  21. writer = csv.writer(f)
  22. writer.writerow(["所属","気分","Count"])
  23. for s in dictS.keys():
  24. for k in dictK.keys():
  25. key = s + '|' + k
  26. if key not in dictSK:
  27. dictSK[key] = 0
  28. writer.writerow([s,k,dictSK[key]])
  29. f.close
  30.  
Runtime error #stdin #stdout #stderr 0.18s 23596KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 3, in <module>
    f = open(path,"r",encoding="utf_8")
FileNotFoundError: [Errno 2] No such file or directory: 'sample1.csv'