Sometimes we get file names without headers. Let’s see how we can read the csv file with pandas by specifying that there are not any headers and to define the column names. We will work with the fertility dataset obtained from IC Irvine.
The txt file looks like:
where as you can see there are no headers. Let’s read it with pandas:
import pandas as pd headers = ['Season', 'Age', 'Diseases', 'Trauma', 'Surgery', 'Fever', 'Alcohol', 'Smoking', 'Sitting', 'Output'] fertility = pd.read_csv('data/fertility_diagnosis.txt', delimiter=',', header=None, names=headers) fertility