Read Without Headers
Assume that you have the following CSV file which is without column names. Let’s see how we can read it with pandas.
my_file.csv
George,25 Maria,30 John,18
We can read the file as follows:
import pandas as pd df = pd.read_csv("my_file.csv", header=None) df
In case we want to give specific names to our column names:
df1 = pd.read_csv("my_file.csv", header=None, names=['colA', 'colB']) df1
Write Without Headers
Now, let’s say that we want to write this dataframe to a csv file but without headers.
df.to_csv('filename.csv', header=False, index=False)
As we can see the filname.csv is without headers!