Export pandas to CSV without Index & Header

  • Post author:

In order to export pandas DataFrame to CSV without index (no row indices) use param index=False and to ignore/remove header use header=False param on to_csv() method. In this article, I will explain how to remove the index and header on the csv file with examples. Note that to_csv() method also supports several other params to write pandas DataFrame to CSV file.

1. pandas to CSV without Index & Header

By default exporting a pandas DataFrame to CSV includes column names on the first row, row index on the first column, and writes a file with a comma-separated delimiter to separate columns. pandas.DataFrame.to_csv() method provides parameters to ignore an index and header while writing.

First, let’s create a DataFrame with a few rows and columns along with index and header names.

# Create a DataFrame
import pandas as pd
import numpy as np
technologies = {
    'Fee' :[22000,25000,np.nan,24000],
df = pd.DataFrame(technologies)

2. pandas to CSV with no Index

pandas DataFrame to CSV with no index can be done by using index=False param of to_csv() method. With this, you can specify ignore index while writing/exporting DataFrame to CSV file.

# Remover column header and index

Writes courses.csv file without index.


3. pandas to CSV without Header

To write DataFrame to CSV without column header (remove column names) use header=False param on to_csv() method.

# Remove header while writing

Writes courses.csv file as.


4. Export without Index and Header

Let’s combine these and see how you can use both removing index and column names on the CSV files.

# Remove header & index while writing
df.to_csv("c:/tmp/courses.csv",header=False, index=False)


In this quick article, you have learned how to remove the header without column names and index while writing DataFrame to CSV file. Use param header=False to remove columns and use index=False to remove index (no row indices) on to_csv() method.

Happy Learning !!

You May Also Like


pandas csv without index


SparkByExamples.com is a Big Data and Spark examples community page, all examples are simple and easy to understand and well tested in our development environment Read more ..

Leave a Reply

You are currently viewing Export pandas to CSV without Index & Header