def to_csv(self, path: Optional[str]=None, sep: str=',', na_rep: str='', columns: Optional[List[Union[(Any, Tuple)]]]=None, header: bool=True, quotechar: str='"', date_format: Optional[str]=None, escapechar: Optional[str]=None, num_files: Optional[int]=None, mode: str='overwrite', partition_cols: Optional[Union[(str, List[str])]]=None, index_col: Optional[Union[(str, List[str])]]=None, **options: Any) -> Optional[str]:
    '\n        Write object to a comma-separated values (csv) file.\n\n        .. note:: pandas-on-Spark `to_csv` writes files to a path or URI. Unlike pandas\',\n            pandas-on-Spark respects HDFS\'s property such as \'fs.default.name\'.\n\n        .. note:: pandas-on-Spark writes CSV files into the directory, `path`, and writes\n            multiple `part-...` files in the directory when `path` is specified.\n            This behaviour was inherited from Apache Spark. The number of files can\n            be controlled by `num_files`.\n\n        Parameters\n        ----------\n        path : str, default None\n            File path. If None is provided the result is returned as a string.\n        sep : str, default \',\'\n            String of length 1. Field delimiter for the output file.\n        na_rep : str, default \'\'\n            Missing data representation.\n        columns : sequence, optional\n            Columns to write.\n        header : bool or list of str, default True\n            Write out the column names. If a list of strings is given it is\n            assumed to be aliases for the column names.\n        quotechar : str, default \'\\"\'\n            String of length 1. Character used to quote fields.\n        date_format : str, default None\n            Format string for datetime objects.\n        escapechar : str, default None\n            String of length 1. Character used to escape `sep` and `quotechar`\n            when appropriate.\n        num_files : the number of files to be written in `path` directory when\n            this is a path.\n        mode : str {\'append\', \'overwrite\', \'ignore\', \'error\', \'errorifexists\'},\n            default \'overwrite\'. Specifies the behavior of the save operation when the\n            destination exists already.\n\n            - \'append\': Append the new data to existing data.\n            - \'overwrite\': Overwrite existing data.\n            - \'ignore\': Silently ignore this operation if data already exists.\n            - \'error\' or \'errorifexists\': Throw an exception if data already exists.\n\n        partition_cols : str or list of str, optional, default None\n            Names of partitioning columns\n        index_col: str or list of str, optional, default: None\n            Column names to be used in Spark to represent pandas-on-Spark\'s index. The index name\n            in pandas-on-Spark is ignored. By default, the index is always lost.\n        options: keyword arguments for additional options specific to PySpark.\n            This kwargs are specific to PySpark\'s CSV options to pass. Check\n            the options in PySpark\'s API documentation for spark.write.csv(...).\n            It has higher priority and overwrites all other options.\n            This parameter only works when `path` is specified.\n\n        Returns\n        -------\n        str or None\n\n        See Also\n        --------\n        read_csv\n        DataFrame.to_delta\n        DataFrame.to_table\n        DataFrame.to_parquet\n        DataFrame.to_spark_io\n\n        Examples\n        --------\n        >>> df = ps.DataFrame(dict(\n        ...    date=list(pd.date_range(\'2012-1-1 12:00:00\', periods=3, freq=\'M\')),\n        ...    country=[\'KR\', \'US\', \'JP\'],\n        ...    code=[1, 2 ,3]), columns=[\'date\', \'country\', \'code\'])\n        >>> df.sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date country  code\n        ... 2012-01-31 12:00:00      KR     1\n        ... 2012-02-29 12:00:00      US     2\n        ... 2012-03-31 12:00:00      JP     3\n\n        >>> print(df.to_csv())  # doctest: +NORMALIZE_WHITESPACE\n        date,country,code\n        2012-01-31 12:00:00,KR,1\n        2012-02-29 12:00:00,US,2\n        2012-03-31 12:00:00,JP,3\n\n        >>> df.cummax().to_csv(path=r\'%s/to_csv/foo.csv\' % path, num_files=1)\n        >>> ps.read_csv(\n        ...    path=r\'%s/to_csv/foo.csv\' % path\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date country  code\n        ... 2012-01-31 12:00:00      KR     1\n        ... 2012-02-29 12:00:00      US     2\n        ... 2012-03-31 12:00:00      US     3\n\n        In case of Series,\n\n        >>> print(df.date.to_csv())  # doctest: +NORMALIZE_WHITESPACE\n        date\n        2012-01-31 12:00:00\n        2012-02-29 12:00:00\n        2012-03-31 12:00:00\n\n        >>> df.date.to_csv(path=r\'%s/to_csv/foo.csv\' % path, num_files=1)\n        >>> ps.read_csv(\n        ...     path=r\'%s/to_csv/foo.csv\' % path\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date\n        ... 2012-01-31 12:00:00\n        ... 2012-02-29 12:00:00\n        ... 2012-03-31 12:00:00\n\n        You can preserve the index in the roundtrip as below.\n\n        >>> df.set_index("country", append=True, inplace=True)\n        >>> df.date.to_csv(\n        ...     path=r\'%s/to_csv/bar.csv\' % path,\n        ...     num_files=1,\n        ...     index_col=["index1", "index2"])\n        >>> ps.read_csv(\n        ...     path=r\'%s/to_csv/bar.csv\' % path, index_col=["index1", "index2"]\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                                     date\n        index1 index2\n        ...    ...    2012-01-31 12:00:00\n        ...    ...    2012-02-29 12:00:00\n        ...    ...    2012-03-31 12:00:00\n        '
    if (('options' in options) and isinstance(options.get('options'), dict) and (len(options) == 1)):
        options = options.get('options')
    if (path is None):
        psdf_or_ser = self
        if ((LooseVersion('0.24') > LooseVersion(pd.__version__)) and isinstance(self, ps.Series)):
            return psdf_or_ser.to_pandas().to_csv(None, sep=sep, na_rep=na_rep, header=header, date_format=date_format, index=False)
        else:
            return psdf_or_ser.to_pandas().to_csv(None, sep=sep, na_rep=na_rep, columns=columns, header=header, quotechar=quotechar, date_format=date_format, escapechar=escapechar, index=False)
    psdf = self
    if isinstance(self, ps.Series):
        psdf = self.to_frame()
    if (columns is None):
        column_labels = psdf._internal.column_labels
    else:
        column_labels = []
        for label in columns:
            if (not is_name_like_tuple(label)):
                label = (label,)
            if (label not in psdf._internal.column_labels):
                raise KeyError(name_like_string(label))
            column_labels.append(label)
    if isinstance(index_col, str):
        index_cols = [index_col]
    elif (index_col is None):
        index_cols = []
    else:
        index_cols = index_col
    if ((header is True) and (psdf._internal.column_labels_level > 1)):
        raise ValueError('to_csv only support one-level index column now')
    elif isinstance(header, list):
        sdf = psdf.to_spark(index_col)
        sdf = sdf.select(([scol_for(sdf, name_like_string(label)) for label in index_cols] + [scol_for(sdf, (str(i) if (label is None) else name_like_string(label))).alias(new_name) for (i, (label, new_name)) in enumerate(zip(column_labels, header))]))
        header = True
    else:
        sdf = psdf.to_spark(index_col)
        sdf = sdf.select(([scol_for(sdf, name_like_string(label)) for label in index_cols] + [scol_for(sdf, (str(i) if (label is None) else name_like_string(label))) for (i, label) in enumerate(column_labels)]))
    if (num_files is not None):
        sdf = sdf.repartition(num_files)
    builder = sdf.write.mode(mode)
    if (partition_cols is not None):
        builder.partitionBy(partition_cols)
    builder._set_opts(sep=sep, nullValue=na_rep, header=header, quote=quotechar, dateFormat=date_format, charToEscapeQuoteEscaping=escapechar)
    builder.options(**options).format('csv').save(path)
    return None
Write object to a comma-separated values (csv) file.

.. note:: pandas-on-Spark `to_csv` writes files to a path or URI. Unlike pandas',
    pandas-on-Spark respects HDFS's property such as 'fs.default.name'.

.. note:: pandas-on-Spark writes CSV files into the directory, `path`, and writes
    multiple `part-...` files in the directory when `path` is specified.
    This behaviour was inherited from Apache Spark. The number of files can
    be controlled by `num_files`.

Parameters
----------
path : str, default None
    File path. If None is provided the result is returned as a string.
sep : str, default ','
    String of length 1. Field delimiter for the output file.
na_rep : str, default ''
    Missing data representation.
columns : sequence, optional
    Columns to write.
header : bool or list of str, default True
    Write out the column names. If a list of strings is given it is
    assumed to be aliases for the column names.
quotechar : str, default '\"'
    String of length 1. Character used to quote fields.
date_format : str, default None
    Format string for datetime objects.
escapechar : str, default None
    String of length 1. Character used to escape `sep` and `quotechar`
    when appropriate.
num_files : the number of files to be written in `path` directory when
    this is a path.
mode : str {'append', 'overwrite', 'ignore', 'error', 'errorifexists'},
    default 'overwrite'. Specifies the behavior of the save operation when the
    destination exists already.

    - 'append': Append the new data to existing data.
    - 'overwrite': Overwrite existing data.
    - 'ignore': Silently ignore this operation if data already exists.
    - 'error' or 'errorifexists': Throw an exception if data already exists.

partition_cols : str or list of str, optional, default None
    Names of partitioning columns
index_col: str or list of str, optional, default: None
    Column names to be used in Spark to represent pandas-on-Spark's index. The index name
    in pandas-on-Spark is ignored. By default, the index is always lost.
options: keyword arguments for additional options specific to PySpark.
    This kwargs are specific to PySpark's CSV options to pass. Check
    the options in PySpark's API documentation for spark.write.csv(...).
    It has higher priority and overwrites all other options.
    This parameter only works when `path` is specified.

Returns
-------
str or None

See Also
--------
read_csv
DataFrame.to_delta
DataFrame.to_table
DataFrame.to_parquet
DataFrame.to_spark_io

Examples
--------
>>> df = ps.DataFrame(dict(
...    date=list(pd.date_range('2012-1-1 12:00:00', periods=3, freq='M')),
...    country=['KR', 'US', 'JP'],
...    code=[1, 2 ,3]), columns=['date', 'country', 'code'])
>>> df.sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
                   date country  code
... 2012-01-31 12:00:00      KR     1
... 2012-02-29 12:00:00      US     2
... 2012-03-31 12:00:00      JP     3

>>> print(df.to_csv())  # doctest: +NORMALIZE_WHITESPACE
date,country,code
2012-01-31 12:00:00,KR,1
2012-02-29 12:00:00,US,2
2012-03-31 12:00:00,JP,3

>>> df.cummax().to_csv(path=r'%s/to_csv/foo.csv' % path, num_files=1)
>>> ps.read_csv(
...    path=r'%s/to_csv/foo.csv' % path
... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
                   date country  code
... 2012-01-31 12:00:00      KR     1
... 2012-02-29 12:00:00      US     2
... 2012-03-31 12:00:00      US     3

In case of Series,

>>> print(df.date.to_csv())  # doctest: +NORMALIZE_WHITESPACE
date
2012-01-31 12:00:00
2012-02-29 12:00:00
2012-03-31 12:00:00

>>> df.date.to_csv(path=r'%s/to_csv/foo.csv' % path, num_files=1)
>>> ps.read_csv(
...     path=r'%s/to_csv/foo.csv' % path
... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
                   date
... 2012-01-31 12:00:00
... 2012-02-29 12:00:00
... 2012-03-31 12:00:00

You can preserve the index in the roundtrip as below.

>>> df.set_index("country", append=True, inplace=True)
>>> df.date.to_csv(
...     path=r'%s/to_csv/bar.csv' % path,
...     num_files=1,
...     index_col=["index1", "index2"])
>>> ps.read_csv(
...     path=r'%s/to_csv/bar.csv' % path, index_col=["index1", "index2"]
... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
                             date
index1 index2
...    ...    2012-01-31 12:00:00
...    ...    2012-02-29 12:00:00
...    ...    2012-03-31 12:00:00
def to_csv(self, path: Optional[str]=None, sep: str=',', na_rep: str=, columns: Optional[List[Union[(Any, Tuple)]]]=None, header: bool=True, quotechar: str='"', date_format: Optional[str]=None, escapechar: Optional[str]=None, num_files: Optional[int]=None, mode: str='overwrite', partition_cols: Optional[Union[(str, List[str])]]=None, index_col: Optional[Union[(str, List[str])]]=None, **options: Any) -> Optional[str]:
    '\n        Write object to a comma-separated values (csv) file.\n\n        .. note:: pandas-on-Spark `to_csv` writes files to a path or URI. Unlike pandas\',\n            pandas-on-Spark respects HDFS\'s property such as \'fs.default.name\'.\n\n        .. note:: pandas-on-Spark writes CSV files into the directory, `path`, and writes\n            multiple `part-...` files in the directory when `path` is specified.\n            This behaviour was inherited from Apache Spark. The number of files can\n            be controlled by `num_files`.\n\n        Parameters\n        ----------\n        path : str, default None\n            File path. If None is provided the result is returned as a string.\n        sep : str, default \',\'\n            String of length 1. Field delimiter for the output file.\n        na_rep : str, default \'\'\n            Missing data representation.\n        columns : sequence, optional\n            Columns to write.\n        header : bool or list of str, default True\n            Write out the column names. If a list of strings is given it is\n            assumed to be aliases for the column names.\n        quotechar : str, default \'\\"\'\n            String of length 1. Character used to quote fields.\n        date_format : str, default None\n            Format string for datetime objects.\n        escapechar : str, default None\n            String of length 1. Character used to escape `sep` and `quotechar`\n            when appropriate.\n        num_files : the number of files to be written in `path` directory when\n            this is a path.\n        mode : str {\'append\', \'overwrite\', \'ignore\', \'error\', \'errorifexists\'},\n            default \'overwrite\'. Specifies the behavior of the save operation when the\n            destination exists already.\n\n            - \'append\': Append the new data to existing data.\n            - \'overwrite\': Overwrite existing data.\n            - \'ignore\': Silently ignore this operation if data already exists.\n            - \'error\' or \'errorifexists\': Throw an exception if data already exists.\n\n        partition_cols : str or list of str, optional, default None\n            Names of partitioning columns\n        index_col: str or list of str, optional, default: None\n            Column names to be used in Spark to represent pandas-on-Spark\'s index. The index name\n            in pandas-on-Spark is ignored. By default, the index is always lost.\n        options: keyword arguments for additional options specific to PySpark.\n            This kwargs are specific to PySpark\'s CSV options to pass. Check\n            the options in PySpark\'s API documentation for spark.write.csv(...).\n            It has higher priority and overwrites all other options.\n            This parameter only works when `path` is specified.\n\n        Returns\n        -------\n        str or None\n\n        See Also\n        --------\n        read_csv\n        DataFrame.to_delta\n        DataFrame.to_table\n        DataFrame.to_parquet\n        DataFrame.to_spark_io\n\n        Examples\n        --------\n        >>> df = ps.DataFrame(dict(\n        ...    date=list(pd.date_range(\'2012-1-1 12:00:00\', periods=3, freq=\'M\')),\n        ...    country=[\'KR\', \'US\', \'JP\'],\n        ...    code=[1, 2 ,3]), columns=[\'date\', \'country\', \'code\'])\n        >>> df.sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date country  code\n        ... 2012-01-31 12:00:00      KR     1\n        ... 2012-02-29 12:00:00      US     2\n        ... 2012-03-31 12:00:00      JP     3\n\n        >>> print(df.to_csv())  # doctest: +NORMALIZE_WHITESPACE\n        date,country,code\n        2012-01-31 12:00:00,KR,1\n        2012-02-29 12:00:00,US,2\n        2012-03-31 12:00:00,JP,3\n\n        >>> df.cummax().to_csv(path=r\'%s/to_csv/foo.csv\' % path, num_files=1)\n        >>> ps.read_csv(\n        ...    path=r\'%s/to_csv/foo.csv\' % path\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date country  code\n        ... 2012-01-31 12:00:00      KR     1\n        ... 2012-02-29 12:00:00      US     2\n        ... 2012-03-31 12:00:00      US     3\n\n        In case of Series,\n\n        >>> print(df.date.to_csv())  # doctest: +NORMALIZE_WHITESPACE\n        date\n        2012-01-31 12:00:00\n        2012-02-29 12:00:00\n        2012-03-31 12:00:00\n\n        >>> df.date.to_csv(path=r\'%s/to_csv/foo.csv\' % path, num_files=1)\n        >>> ps.read_csv(\n        ...     path=r\'%s/to_csv/foo.csv\' % path\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                           date\n        ... 2012-01-31 12:00:00\n        ... 2012-02-29 12:00:00\n        ... 2012-03-31 12:00:00\n\n        You can preserve the index in the roundtrip as below.\n\n        >>> df.set_index("country", append=True, inplace=True)\n        >>> df.date.to_csv(\n        ...     path=r\'%s/to_csv/bar.csv\' % path,\n        ...     num_files=1,\n        ...     index_col=["index1", "index2"])\n        >>> ps.read_csv(\n        ...     path=r\'%s/to_csv/bar.csv\' % path, index_col=["index1", "index2"]\n        ... ).sort_values(by="date")  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n                                     date\n        index1 index2\n        ...    ...    2012-01-31 12:00:00\n        ...    ...    2012-02-29 12:00:00\n        ...    ...    2012-03-31 12:00:00\n        '
    if (('options' in options) and isinstance(options.get('options'), dict) and (len(options) == 1)):
        options = options.get('options')
    if (path is None):
        psdf_or_ser = self
        if ((LooseVersion('0.24') > LooseVersion(pd.__version__)) and isinstance(self, ps.Series)):
            return psdf_or_ser.to_pandas().to_csv(None, sep=sep, na_rep=na_rep, header=header, date_format=date_format, index=False)
        else:
            return psdf_or_ser.to_pandas().to_csv(None, sep=sep, na_rep=na_rep, columns=columns, header=header, quotechar=quotechar, date_format=date_format, escapechar=escapechar, index=False)
    psdf = self
    if isinstance(self, ps.Series):
        psdf = self.to_frame()
    if (columns is None):
        column_labels = psdf._internal.column_labels
    else:
        column_labels = []
        for label in columns:
            if (not is_name_like_tuple(label)):
                label = (label,)
            if (label not in psdf._internal.column_labels):
                raise KeyError(name_like_string(label))
            column_labels.append(label)
    if isinstance(index_col, str):
        index_cols = [index_col]
    elif (index_col is None):
        index_cols = []
    else:
        index_cols = index_col
    if ((header is True) and (psdf._internal.column_labels_level > 1)):
        raise ValueError('to_csv only support one-level index column now')
    elif isinstance(header, list):
        sdf = psdf.to_spark(index_col)
        sdf = sdf.select(([scol_for(sdf, name_like_string(label)) for label in index_cols] + [scol_for(sdf, (str(i) if (label is None) else name_like_string(label))).alias(new_name) for (i, (label, new_name)) in enumerate(zip(column_labels, header))]))
        header = True
    else:
        sdf = psdf.to_spark(index_col)
        sdf = sdf.select(([scol_for(sdf, name_like_string(label)) for label in index_cols] + [scol_for(sdf, (str(i) if (label is None) else name_like_string(label))) for (i, label) in enumerate(column_labels)]))
    if (num_files is not None):
        sdf = sdf.repartition(num_files)
    builder = sdf.write.mode(mode)
    if (partition_cols is not None):
        builder.partitionBy(partition_cols)
    builder._set_opts(sep=sep, nullValue=na_rep, header=header, quote=quotechar, dateFormat=date_format, charToEscapeQuoteEscaping=escapechar)
    builder.options(**options).format('csv').save(path)
    return None