code: def _convert_to_df(in_file, freq, raw_file):
      
      dat = defaultdict(Counter)
      if isinstance(in_file, (str, unicode)):
          with open(in_file) as in_handle:
              for line in in_handle:
                  cols = line.strip().split("\t")
                  counts = freq[cols[3]]
                  dat = _expand(dat, counts, int(cols[1]), int(cols[2]))
      else:
          if raw_file:
              out_handle = open(raw_file, "w")
          for name in in_file:
              counts = freq[name]
              if raw_file:
                  print("%s\t%s\t%s\t%s\t%s\t%s" % ("chr", in_file[name][0], in_file[name][1], name, sum(counts.values()), "+"), file=out_handle, end="")
              dat = _expand(dat, counts, in_file[name][0], in_file[name][1])
  
      for s in dat:
          for p in dat[s]:
              dat[s][p] = mlog2(dat[s][p] + 1)
      return dat
docs: convert data frame into table with pandas