How to export Pandas DataFrame to a CSV file? Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue 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 : # 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. # 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. # 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: Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 10 Jul, 2020 Like Article Save Article Previous Check if a value exists in a DataFrame using in & not in operator in Python-Pandas Next Get Day from date in Pandas - Python Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Export Pandas dataframe to a CSV file How to create multiple CSV files from existing CSV file using Pandas ? How to read a CSV file to a Dataframe with custom delimiter in Pandas? Pandas - DataFrame to CSV file using tab separator How to Append Pandas DataFrame to Existing CSV File? PyMongoArrow: Export and Import MongoDB data to Pandas DataFrame and NumPy How to import and export data using CSV files in PostgreSQL Saving a Pandas Dataframe as a CSV Convert CSV to Pandas Dataframe How to Merge multiple CSV Files into a single Pandas dataframe ? Complete Tutorials Python API Tutorial: Getting Started with APIs Advanced Python Tutorials Python Automation Tutorial OpenAI Python API - Complete Guide Pandas AI: The Generative AI Python Library Like rutujakawade24 Follow Article Tags : Python pandas-dataFrame Python-pandas Python Practice Tags : python Additional Information Vote for difficulty : Easy Normal Medium Hard Expert