code: def _hfd5_from_dataframe(ratings, movies, outputfilename):
      # transform ratings dataframe into a sparse matrix
      m = coo_matrix(
          (
              ratings["rating"].astype(np.float32),
              (ratings["movieId"], ratings["userId"]),
          )
      ).tocsr()
  
      with h5py.File(outputfilename, "w") as f:
          # write out the ratings matrix
          g = f.create_group("movie_user_ratings")
          g.create_dataset("data", data=m.data)
          g.create_dataset("indptr", data=m.indptr)
          g.create_dataset("indices", data=m.indices)
  
          # write out the titles as a numpy array
          titles = np.empty(
              shape=(movies.movieId.max() + 1,), dtype=np.object
          )
          titles[movies.movieId] = movies.title
          dt = h5py.special_dtype(vlen=str)
          dset = f.create_dataset("movie", (len(titles),), dtype=dt)
          dset[:] = titles
  
file_path: implicit/implicit/datasets/movielens.py
imports: import logging
  import os
  import h5py
  import numpy
  from scipy.sparse import coo_matrix, csr_matrix
  from implicit.datasets import _download
label_desc: Use image node_id 6 for calling a global function with example usage: _hfd5_from_dataframe(ratings, movies, outputfilename) without return types