pandas Save pandas dataframe to a csv file

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


path_or_bufstring or file handle, default None File path or object, if None is provided the result is returned as a string.
sepcharacter, default ‘,’ Field delimiter for the output file.
na_repstring, default ‘’ Missing data representation
float_formatstring, default None Format string for floating point numbers
columnssequence, optional Columns to write
headerboolean or list of string, default True Write out column names. If a list of string is given it is assumed to be aliases for the column names
indexboolean, default True Write row names (index)
index_labelstring or sequence, or False, default None Column label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in R
nanRepNone deprecated, use na_rep
modestr Python write mode, default ‘w’
encodingstring, optional A string representing the encoding to use in the output file, defaults to ‘ascii’ on Python 2 and ‘utf-8’ on Python 3.
compressionstring, optional a string representing the compression to use in the output file, allowed values are ‘gzip’, ‘bz2’, ‘xz’, only used when the first argument is a filename
line_terminatorstring, default ‘n’ The newline character or character sequence to use in the output file
quotingoptional constant from csv module defaults to csv.QUOTE_MINIMAL
quotecharstring (length 1), default ‘”’ character used to quote fields
doublequoteboolean, default True Control quoting of quotechar inside a field
escapecharstring (length 1), default None character used to escape sep and quotechar when appropriate
chunksizeint or None rows to write at a time
tupleize_colsboolean, default False write multi_index columns as a list of tuples (if True) or new (expanded format) if False)
date_formatstring, default None Format string for datetime objects
decimalstring, default ‘.’ Character recognized as decimal separator. E.g. use ‘,’ for European data

Got any pandas Question?