code: def write_top_half(f, row_metadata_df, col_metadata_df, metadata_null, filler_null):
      
      # Initialize the top half of the gct including the third line
      size_of_top_half_df = (1 + col_metadata_df.shape[1],
                             1 + row_metadata_df.shape[1] + col_metadata_df.shape[0])
  
      top_half_df = pd.DataFrame(np.full(size_of_top_half_df, filler_null, dtype=object))
  
      # Assemble the third line of the gct: "id", then rhds, then cids
      top_half_df.iloc[0, :] = np.hstack(("id", row_metadata_df.columns.values, col_metadata_df.index.values))
  
      # Insert the chds
      top_half_df.iloc[range(1, top_half_df.shape[0]), 0] = col_metadata_df.columns.values
  
      # Insert the column metadata, but first convert to strings and replace NaNs
      col_metadata_indices = (range(1, top_half_df.shape[0]),
                              range(1 + row_metadata_df.shape[1], top_half_df.shape[1]))
      # pd.DataFrame.at to insert into dataframe(python3)
      top_half_df.at[col_metadata_indices[0], col_metadata_indices[1]] = (
          col_metadata_df.astype(str).replace("nan", value=metadata_null).T.values)
  
      # Write top_half_df to file
      top_half_df.to_csv(f, header=False, index=False, sep="\t")
docs: Write the top half of the gct file: top-left filler values, row metadata
      headers, and top-right column metadata.
  
      Args:
          f (file handle): handle for output file
          row_metadata_df (pandas df)
          col_metadata_df (pandas df)
          metadata_null (string): how to represent missing values in the metadata
          filler_null (string): what value to fill the top-left filler block with
  
      Returns:
          None