How can I read .names file?

Hi,

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',
            'relationship','race','sex','capital_gain','capital_loss','hours_per_week','native_country',
            'high_income']

income = pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data',
            names=col_name)

Attribute names:
http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.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:
    print(f.read())
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