Exporting a DataFrame to a CSV File
CSV File
To save a DataFrame as a CSV file, we can use the built-in Pandas df.to_csv() method is a built-in function in Pandas that allows you to save a Pandas DataFrame as a CSV file.
df.to_csv('filename.csv', sep=',', index=False)
Parameter:
sep
The sep parameter specifies the separator that should be used to separate values in the CSV file. By default, it is set to , for comma-separated values.
Parameter:
index
The index parameter is a boolean value that determines whether to include the index of the DataFrame in the CSV file. By default, it is set to False, which means the index is not included.
Excel File
df.to_excel("filename.xlsx", sheet_name='sheet1',... )
# Name of sheet which will contain the DataFrame
JSON File
df.to_json('filename.json')