code: def generate_statistics_from_csv(
      data_location: Text,
      column_names: Optional[List[types.FeatureName]] = None,
      delimiter: Text = ",",
      output_path: Optional[bytes] = None,
      stats_options: options.StatsOptions = options.StatsOptions(),
      pipeline_options: Optional[PipelineOptions] = None,
      compression_type: Text = CompressionTypes.AUTO,
  ) -> statistics_pb2.DatasetFeatureStatisticsList:
      """Compute data statistics from CSV files.
  
      Runs a Beam pipeline to compute the data statistics and return the result
      data statistics proto.
  
      This is a convenience method for users with data in CSV format.
      Users with data in unsupported file/data formats, or users who wish
      to create their own Beam pipelines need to use the 'GenerateStatistics'
      PTransform API directly instead.
  
      Args:
        data_location: The location of the input data files.
        column_names: A list of column names to be treated as the CSV header. Order
          must match the order in the input CSV files. If this argument is not
          specified, we assume the first line in the input CSV files as the
          header. Note that this option is valid only for 'csv' input file format.
        delimiter: A one-character string used to separate fields in a CSV file.
        output_path: The file path to output data statistics result to. If None, we
          use a temporary directory. It will be a TFRecord file containing a single
          data statistics proto, and can be read with the 'load_statistics' API.
          If you run this function on Google Cloud, you must specify an
          output_path. Specifying None may cause an error.
        stats_options: `tfdv.StatsOptions` for generating data statistics.
        pipeline_options: Optional beam pipeline options. This allows users to
          specify various beam pipeline execution parameters like pipeline runner
          (DirectRunner or DataflowRunner), cloud dataflow service project id, etc.
          See https://cloud.google.com/dataflow/pipelines/specifying-exec-params for
          more details.
        compression_type: Used to handle compressed input files. Default value is
          CompressionTypes.AUTO, in which case the file_path's extension will be
          used to detect the compression.
  
      Returns:
        A DatasetFeatureStatisticsList proto.
      """
      if output_path is None:
          output_path = os.path.join(
              tempfile.mkdtemp(), "data_stats.tfrecord"
          )
      output_dir_path = os.path.dirname(output_path)
      if not tf.io.gfile.exists(output_dir_path):
          tf.io.gfile.makedirs(output_dir_path)
  
      batch_size = (
          stats_options.desired_batch_size
          if stats_options.desired_batch_size
          and stats_options.desired_batch_size > 0
          else constants.DEFAULT_DESIRED_INPUT_BATCH_SIZE
      )
      # PyLint doesn't understand Beam PTransforms.
      # pylint: disable=no-value-for-parameter
      with beam.Pipeline(options=pipeline_options) as p:
          # If a header is not provided, assume the first line in a file
          # to be the header.
          skip_header_lines = 1 if column_names is None else 0
          if column_names is None:
              column_names = get_csv_header(
                  data_location, delimiter, compression_type
              )
          _ = (
              p
              | "ReadData"
              >> beam.io.textio.ReadFromText(
                  file_pattern=data_location,
                  skip_header_lines=skip_header_lines,
                  compression_type=compression_type,
              )
              | "DecodeData"
              >> csv_decoder.DecodeCSV(
                  column_names=column_names,
                  delimiter=delimiter,
                  schema=stats_options.schema
                  if stats_options.infer_type_from_schema
                  else None,
                  desired_batch_size=batch_size,
              )
              | "GenerateStatistics"
              >> stats_api.GenerateStatistics(stats_options)
              | "WriteStatsOutput"
              >> stats_api.WriteStatisticsToTFRecord(output_path)
          )
      return stats_util.load_statistics(output_path)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import csv
  import gzip
  import io
  import multiprocessing
  import os
  import tempfile
  from typing import Any, List, Optional, Text, cast
  import apache_beam
  from apache_beam.io.filesystem import CompressionTypes
  from apache_beam.options.pipeline_options import PipelineOptions
  from joblib import delayed
  from joblib import Parallel
  import numpy
  from pandas import DataFrame
  import pyarrow
  import tensorflow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.api import stats_api
  from tensorflow_data_validation.coders import csv_decoder
  from tensorflow_data_validation.statistics import stats_impl
  from tensorflow_data_validation.statistics import stats_options
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.utils import stats_util
  from tfx_bsl.arrow import table_util
  from tfx_bsl.tfxio import tf_example_record
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: generate_statistics_from_csv(data_location, column_names, delimiter, output_path, stats_options, pipeline_options, compression_type) and returns: stats_util