nodes: 0, module; 1, function_definition; 2, function_name:export_csv; 3, parameters; 4, block; 5, identifier:self; 6, identifier:path; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, if_statement; 14, if_statement; 15, assert_statement; 16, expression_statement; 17, with_statement; 18, identifier:idx; 19, None; 20, identifier:header; 21, None; 22, identifier:formatted; 23, False; 24, identifier:sort_idx; 25, True; 26, identifier:fmt; 27, string; 28, comment:"""
          Export to a csv file
  
          Parameters
          ----------
          path : str
              path of the csv file to save
          idx : None or array-like, optional
              the indices of the variables to export. Export all by default
          header : None or array-like, optional
              customized header if not `None`. Use the names from the lst file
              by default
          formatted : bool, optional
              Use LaTeX-formatted header. Does not apply when using customized
              header
          sort_idx : bool, optional
              Sort by idx or not, # TODO: implement sort
          fmt : str
              cell formatter
          """; 29, not_operator; 30, block; 31, not_operator; 32, block; 33, comparison_operator:len(idx) == len(header); 34, string:"Idx length does not match header length"; 35, assignment; 36, with_clause; 37, block; 38, string_content:%.18e; 39, identifier:idx; 40, expression_statement; 41, identifier:header; 42, expression_statement; 43, call; 44, call; 45, identifier:body; 46, call; 47, with_item; 48, expression_statement; 49, expression_statement; 50, assignment; 51, assignment; 52, identifier:len; 53, argument_list; 54, identifier:len; 55, argument_list; 56, attribute; 57, argument_list; 58, as_pattern; 59, call; 60, call; 61, identifier:idx; 62, attribute; 63, identifier:header; 64, call; 65, identifier:idx; 66, identifier:header; 67, identifier:self; 68, identifier:get_values; 69, identifier:idx; 70, call; 71, as_pattern_target; 72, attribute; 73, argument_list; 74, attribute; 75, argument_list; 76, identifier:self; 77, identifier:_idx; 78, attribute; 79, argument_list; 80, identifier:open; 81, argument_list; 82, identifier:fd; 83, identifier:fd; 84, identifier:write; 85, binary_operator:','.join(header) + '\n'; 86, identifier:np; 87, identifier:savetxt; 88, identifier:fd; 89, identifier:body; 90, keyword_argument; 91, keyword_argument; 92, identifier:self; 93, identifier:get_header; 94, identifier:idx; 95, keyword_argument; 96, identifier:path; 97, string; 98, call; 99, string; 100, identifier:fmt; 101, identifier:fmt; 102, identifier:delimiter; 103, string; 104, identifier:formatted; 105, identifier:formatted; 106, string_content:w; 107, attribute; 108, argument_list; 109, string_content; 110, string_content:,; 111, string; 112, identifier:join; 113, identifier:header; 114, escape_sequence:\n; 115, string_content:,
code: def export_csv(self, path, idx=None, header=None, formatted=False,
                     sort_idx=True, fmt='%.18e'):
          """
          Export to a csv file
  
          Parameters
          ----------
          path : str
              path of the csv file to save
          idx : None or array-like, optional
              the indices of the variables to export. Export all by default
          header : None or array-like, optional
              customized header if not `None`. Use the names from the lst file
              by default
          formatted : bool, optional
              Use LaTeX-formatted header. Does not apply when using customized
              header
          sort_idx : bool, optional
              Sort by idx or not, # TODO: implement sort
          fmt : str
              cell formatter
          """
          if not idx:
              idx = self._idx
          if not header:
              header = self.get_header(idx, formatted=formatted)
  
          assert len(idx) == len(header), \
              "Idx length does not match header length"
  
          body = self.get_values(idx)
  
          with open(path, 'w') as fd:
              fd.write(','.join(header) + '\n')
              np.savetxt(fd, body, fmt=fmt, delimiter=',')