How to set column names when importing a CSV into a Pandas DataFrame in Python

Importing a .csv to a pandas.DataFrame using pandas.read_csv() will set the column names in the DataFrame to be the first row in the .csv, by default. However, it is possible to set different column names when importing the .csv.

Solution for How to set column names when importing a CSV into a Pandas DataFrame in Python : You can use pandas.read_csv() to set column names when reading in a csv Call pandas.read_csv(filepath_or_buffer, names = None) with filepath_or_buffer set to the filename of the .csv and names set to the list of column names. The column names will be assigned to each column of the resultant DataFrame in the order they appear in names.

Call pandas.read_csv(filepath_or_buffer, header=None) with header set to None to create a DataFrame with no column names.

df = pd.read_csv("sample_file.csv", header=None)


how-to-set-column-names-when-importing-a-csv-into-a-pandas-dataframe-in-python