How can I read .names file?


Does anyone know how to read .names files?

For example, with this dataset:

I want to read the attribute names directly instead of using a list:

import pandas as pd

col_name = ['age','workclass','fnlwgt','education','education_num','marital_status','occupation',

income = pd.read_csv('',

Attribute names:

hello, the adult.names is a file that has some information. use pythons built in open function to read the file contents. You’ll have to download that file.

with open("adult.names") as f:
1 Like

I haven’t worked with .names file, but they are not meant to be opened as csv files because they don’t have comma separate values.

You can open the file using any text editor on your computer (or through python as the other answer suggests), and you should see that it contains descriptive text related to the dataset.

You can try to identify how the text is separated (commas, spaces or tabs etc). Something like -

t = pd.read_csv("adult.names", sep="\t")

But that t dataframe is not going to be of value per se, because it’s just text describing the dataset and some other things.

1 Like