To export a pandas dataframe to a csv file in Python, you can use the to_csv
function.
Here is an example:
main.py104 chars4 lines
In this example, we first create a pandas dataframe df
with two columns 'a' and 'b' and two rows. Then, we use the to_csv
function to export the dataframe to a csv file named 'my_file.csv', without writing the index column.
By default, the to_csv
function uses commas as the delimiter and writes strings in quotes. However, you can customize these options by specifying additional parameters in the function.
For more information on to_csv
and other options for exporting dataframes in pandas, you can refer to the pandas documentation.
gistlibby LogSnag