docs: def write_csv(graph, prefix):
      """
      Write ``graph`` as tables of nodes (``prefix-nodes.csv``) and edges
      (``prefix-edges.csv``).
  
      Parameters
      ----------
      graph : :ref:`networkx.Graph <networkx:graph>`
      prefix : str
      """
      node_headers = list(set([a for n, attrs in graph.nodes(data=True)
                               for a in attrs.keys()]))
      edge_headers = list(set([a for s, t, attrs in graph.edges(data=True)
                               for a in attrs.keys()]))
  
      value = lambda attrs, h: _recast_value(attrs[h]) if h in attrs else ''
      with open(prefix + '_nodes.csv', 'w') as f:
          writer = csv.writer(f)
          writer.writerow(['node'] + node_headers)
          for n, attrs in graph.nodes(data=True):
              values = map(value, repeat(attrs, len(node_headers)), node_headers)
              writer.writerow([_recast_value(n)] + list(values))
  
      with open(prefix + '_edges.csv', 'w') as f:
          writer = csv.writer(f)
          writer.writerow(['source', 'target'] + edge_headers)
          for s, t, attrs in graph.edges(data=True):
              values = map(value, repeat(attrs, len(edge_headers)), edge_headers)
              writer.writerow([_recast_value(s), _recast_value(t)] + list(values))