r"""Write a dataframe into a delimiter-separated file. Parameters ---------- df : pandas.DataFrame The pandas dataframe to save to a file. directory : str Full directory specification. filename : str Name of the file to write, excluding the ``extension``.
(df, directory, filename, extension, separator,
index=False, index_label=None, columns=None)
| 175 | # |
| 176 | |
| 177 | def write_frame(df, directory, filename, extension, separator, |
| 178 | index=False, index_label=None, columns=None): |
| 179 | r"""Write a dataframe into a delimiter-separated file. |
| 180 | |
| 181 | Parameters |
| 182 | ---------- |
| 183 | df : pandas.DataFrame |
| 184 | The pandas dataframe to save to a file. |
| 185 | directory : str |
| 186 | Full directory specification. |
| 187 | filename : str |
| 188 | Name of the file to write, excluding the ``extension``. |
| 189 | extension : str |
| 190 | File name extension, e.g., ``csv``. |
| 191 | separator : str |
| 192 | The delimiter between fields in the file. |
| 193 | index : bool, optional |
| 194 | If ``True``, write the row names (index). |
| 195 | index_label : str, optional |
| 196 | A column label for the ``index``. |
| 197 | columns : str, optional |
| 198 | A list of column names. |
| 199 | |
| 200 | Returns |
| 201 | ------- |
| 202 | None : None |
| 203 | |
| 204 | """ |
| 205 | file_only = PSEP.join([filename, extension]) |
| 206 | file_all = SSEP.join([directory, file_only]) |
| 207 | logger.info("Writing data frame to %s", file_all) |
| 208 | try: |
| 209 | df.to_csv(file_all, sep=separator, index=index, |
| 210 | index_label=index_label, columns=columns) |
| 211 | except: |
| 212 | logger.info("Could not write data frame to %s", file_all) |
| 213 | |
| 214 | |
| 215 | # |
no outgoing calls
no test coverage detected