Store Dask DataFrame to CSV files One filename per partition will be created. You can specify the filenames in a variety of ways. Use a globstring:: >>> df.to_csv('/path/to/data/export-*.csv') # doctest: +SKIP The * will be replaced by the increasing sequence 0, 1, 2, .
(
df,
filename,
single_file=False,
encoding="utf-8",
mode="wt",
name_function=None,
compression=None,
compute=True,
scheduler=None,
storage_options=None,
header_first_partition_only=None,
compute_kwargs=None,
**kwargs,
)
| 765 | |
| 766 | |
| 767 | def to_csv( |
| 768 | df, |
| 769 | filename, |
| 770 | single_file=False, |
| 771 | encoding="utf-8", |
| 772 | mode="wt", |
| 773 | name_function=None, |
| 774 | compression=None, |
| 775 | compute=True, |
| 776 | scheduler=None, |
| 777 | storage_options=None, |
| 778 | header_first_partition_only=None, |
| 779 | compute_kwargs=None, |
| 780 | **kwargs, |
| 781 | ): |
| 782 | """ |
| 783 | Store Dask DataFrame to CSV files |
| 784 | |
| 785 | One filename per partition will be created. You can specify the |
| 786 | filenames in a variety of ways. |
| 787 | |
| 788 | Use a globstring:: |
| 789 | |
| 790 | >>> df.to_csv('/path/to/data/export-*.csv') # doctest: +SKIP |
| 791 | |
| 792 | The * will be replaced by the increasing sequence 0, 1, 2, ... |
| 793 | |
| 794 | :: |
| 795 | |
| 796 | /path/to/data/export-0.csv |
| 797 | /path/to/data/export-1.csv |
| 798 | |
| 799 | Use a globstring and a ``name_function=`` keyword argument. The |
| 800 | name_function function should expect an integer and produce a string. |
| 801 | Strings produced by name_function must preserve the order of their |
| 802 | respective partition indices. |
| 803 | |
| 804 | >>> from datetime import date, timedelta |
| 805 | >>> def name(i): |
| 806 | ... return str(date(2015, 1, 1) + i * timedelta(days=1)) |
| 807 | |
| 808 | >>> name(0) |
| 809 | '2015-01-01' |
| 810 | >>> name(15) |
| 811 | '2015-01-16' |
| 812 | |
| 813 | >>> df.to_csv('/path/to/data/export-*.csv', name_function=name) # doctest: +SKIP |
| 814 | |
| 815 | :: |
| 816 | |
| 817 | /path/to/data/export-2015-01-01.csv |
| 818 | /path/to/data/export-2015-01-02.csv |
| 819 | ... |
| 820 | |
| 821 | You can also provide an explicit list of paths:: |
| 822 | |
| 823 | >>> paths = ['/path/to/data/alice.csv', '/path/to/data/bob.csv', ...] # doctest: +SKIP |
| 824 | >>> df.to_csv(paths) # doctest: +SKIP |