Render dataframe as comma-separated file.
(
self,
path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None,
encoding: str | None = None,
sep: str = ",",
columns: Sequence[Hashable] | None = None,
index_label: IndexLabel | None = None,
mode: str = "w",
compression: CompressionOptions = "infer",
quoting: int | None = None,
quotechar: str = '"',
lineterminator: str | None = None,
chunksize: int | None = None,
date_format: str | None = None,
doublequote: bool = True,
escapechar: str | None = None,
errors: str = "strict",
storage_options: StorageOptions | None = None,
)
| 974 | return save_to_buffer(string, buf=buf, encoding=encoding) |
| 975 | |
| 976 | def to_csv( |
| 977 | self, |
| 978 | path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None, |
| 979 | encoding: str | None = None, |
| 980 | sep: str = ",", |
| 981 | columns: Sequence[Hashable] | None = None, |
| 982 | index_label: IndexLabel | None = None, |
| 983 | mode: str = "w", |
| 984 | compression: CompressionOptions = "infer", |
| 985 | quoting: int | None = None, |
| 986 | quotechar: str = '"', |
| 987 | lineterminator: str | None = None, |
| 988 | chunksize: int | None = None, |
| 989 | date_format: str | None = None, |
| 990 | doublequote: bool = True, |
| 991 | escapechar: str | None = None, |
| 992 | errors: str = "strict", |
| 993 | storage_options: StorageOptions | None = None, |
| 994 | ) -> str | None: |
| 995 | """ |
| 996 | Render dataframe as comma-separated file. |
| 997 | """ |
| 998 | from pandas.io.formats.csvs import CSVFormatter |
| 999 | |
| 1000 | if path_or_buf is None: |
| 1001 | created_buffer = True |
| 1002 | path_or_buf = StringIO() |
| 1003 | else: |
| 1004 | created_buffer = False |
| 1005 | |
| 1006 | csv_formatter = CSVFormatter( |
| 1007 | path_or_buf=path_or_buf, |
| 1008 | lineterminator=lineterminator, |
| 1009 | sep=sep, |
| 1010 | encoding=encoding, |
| 1011 | errors=errors, |
| 1012 | compression=compression, |
| 1013 | quoting=quoting, |
| 1014 | cols=columns, |
| 1015 | index_label=index_label, |
| 1016 | mode=mode, |
| 1017 | chunksize=chunksize, |
| 1018 | quotechar=quotechar, |
| 1019 | date_format=date_format, |
| 1020 | doublequote=doublequote, |
| 1021 | escapechar=escapechar, |
| 1022 | storage_options=storage_options, |
| 1023 | formatter=self.fmt, |
| 1024 | ) |
| 1025 | csv_formatter.save() |
| 1026 | |
| 1027 | if created_buffer: |
| 1028 | assert isinstance(path_or_buf, StringIO) |
| 1029 | content = path_or_buf.getvalue() |
| 1030 | path_or_buf.close() |
| 1031 | return content |
| 1032 | |
| 1033 | return None |
no test coverage detected