Read CSV - Selecting the Row that Contains Column Header

Import and Export

To select which row to use as a header when reading a csv into a Pandas dataframe, use the "header" parameter to pass the row index of the row that contains the headers.

In the example below, we are using the values in the 3rd row for the headers of the dataframe.

 1|  import pandas as pd
 3|  df = pd.read_csv('sales.csv', header=2)
1 Upvote
Tags: Csv | Read_csv
Did you find this snippet useful?

Sign up to bookmark this in your snippet library