class_docstr: Dump all episode metrics to a ``result.csv``.
  
  This is not the correct implementation. It's only used for first iteration.
class_docstr_tok: ["Dump","all","episode","metrics","to","a","``","result.csv","``",".","This","is","not","the","correct","implementation",".","It","'s","only","used","for","first","iteration","."]
code: def __init__(
      self,
      output_dir: Path,
      loglevel: int | LogLevel = LogLevel.PERIODIC,
  ) -> None:
      super().__init__(loglevel)
      self.output_dir = output_dir
      self.output_dir.mkdir(exist_ok=True)
  
imports: from __future__ import annotations
  import logging
  from collections import defaultdict
  from enum import IntEnum
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, List, Sequence, Set, Tuple, TypeVar
  import numpy
  import pandas
  from qlib.log import get_module_logger
label_desc: Use image node_id 1 to create a new CsvWriter object from inherited base classes: LogWriter with example: obj = CsvWriter(output_dir, loglevel)