How to export Pandas DataFrame to a CSV file? Last Updated : 10 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Let us see how to export a Pandas DataFrame to a CSV file. We will be using the to_csv() function to save a DataFrame as a CSV file. DataFrame.to_csv() Syntax : to_csv(parameters) Parameters : path_or_buf : File path or object, if None is provided the result is returned as a string. sep : String of length 1. Field delimiter for the output file. na_rep : Missing data representation. float_format : Format string for floating point numbers. columns : Columns to write. header : If a list of strings is given it is assumed to be aliases for the column names. index : Write row names (index). index_label : Column label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. mode : Python write mode, default ‘w’. encoding : A string representing the encoding to use in the output file. compression : Compression mode among the following possible values: {‘infer’, ‘gzip’, ‘bz2’, ‘zip’, ‘xz’, None}. quoting : Defaults to csv.QUOTE_MINIMAL. quotechar : String of length 1. Character used to quote fields. line_terminator : The newline character or character sequence to use in the output file. chunksize : Rows to write at a time. date_format : Format string for datetime objects. doublequote : Control quoting of quotechar inside a field. escapechar : String of length 1. Character used to escape sep and quotechar when appropriate. decimal : Character recognized as decimal separator. E.g. use ‘,’ for European data. Returns : None or str Example 1 : Python3 1== # importing the module import pandas as pd # creating the DataFrame my_df = {'Name': ['Rutuja', 'Anuja'], 'ID': [1, 2], 'Age': [20, 19]} df = pd.DataFrame(my_df) # displaying the DataFrame print('DataFrame:\n', df) # saving the DataFrame as a CSV file gfg_csv_data = df.to_csv('GfG.csv', index = True) print('\nCSV String:\n', gfg_csv_data) Output : Before executing the code: After executing the code: We can clearly see the .csv file created. Also, the output of the above code includes the index, as follows. Example 2 : Converting to a CSV file without the index. If we wish not to include the index, then in the index parameter assign the value False. Python3 1== # importing the module import pandas as pd # creating the DataFrame my_df = {'Name': ['Rutuja', 'Anuja'], 'ID': [1, 2], 'Age': [20, 19]} df = pd.DataFrame(my_df) # displaying the DataFrame print('DataFrame:\n', df) # saving the DataFrame as a CSV file gfg_csv_data = df.to_csv('GfG.csv', index = False) print('\nCSV String:\n', gfg_csv_data) Output: Example 3 : Converting to a CSV file without the header of the rows. If we wish not to include the header, then in the headerparameter assign the value False. Python3 1== # importing the module import pandas as pd # creating the DataFrame my_df = {'Name': ['Rutuja', 'Anuja'], 'ID': [1, 2], 'Age': [20, 19]} df = pd.DataFrame(my_df) # displaying the DataFrame print('DataFrame:\n', df) # saving the DataFrame as a CSV file gfg_csv_data = df.to_csv('GfG.csv', header = False) print('\nCSV String:\n', gfg_csv_data) Output: Comment More infoAdvertise with us Next Article How to add header row to a Pandas Dataframe? R rutujakawade24 Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads Export Pandas dataframe to a CSV file When working on a Data Science project one of the key tasks is data management which includes data collection, cleaning and storage. Once our data is cleaned and processed itâs essential to save it in a structured format for further analysis or sharing.A CSV (Comma-Separated Values) file is a widely 2 min read How to Append Pandas DataFrame to Existing CSV File? In this discussion, we'll explore the process of appending a Pandas DataFrame to an existing CSV file using Python. Add Pandas DataFrame to an Existing CSV File. To achieve this, we can utilize the to_csv() function in Pandas with the 'a' parameter to write the DataFrame to the CSV file in append mo 3 min read Exporting Pandas DataFrame to JSON File Pandas a powerful Python library for data manipulation provides the to_json() function to convert a DataFrame into a JSON file and the read_json() function to read a JSON file into a DataFrame.In this article we will explore how to export a Pandas DataFrame to a JSON file with detailed explanations 2 min read Exporting a Pandas DataFrame to an Excel file Sometimes we need an Excel file for reporting, so as a coder we will see how to export Pandas DataFrame to an Excel file. The to_excel() function in the Pandas library is utilized to export a DataFrame to an Excel sheet with the .xlsx extension.Syntax# saving the exceldataframe_name.to_excel(file_na 4 min read How to add header row to a Pandas Dataframe? A header necessarily stores the names or headings for each of the columns. It helps the user to identify the role of the respective column in the data frame. The top row containing column names is called the header row of the data frame. There are two approaches to add header row to a Pandas Datafra 4 min read How to load a TSV file into a Pandas DataFrame? In this article, we will discuss how to load a TSV file into a Pandas Dataframe. The idea is extremely simple we only have to first import all the required libraries and then load the data set by using various methods in Python. Dataset Used:  data.tsv Using read_csv() to load a TSV file into a Pan 1 min read Like