the dummy encoding used in statistics for simplicitywe encode each category with different binary feature in statisticsit is common to encode categorical feature with different possible values into - features (the last one is represented as all zerosthis is done to simplify the analysis (more technicallythis will avoid making the data matrix rank-deficientthere are two ways to convert your data to one-hot encoding of categorical variablesusing either pandas or scikit-learn at the time of writingusing pandas is slightly easierso let' go this route first we load the data using pandas from comma-separated values (csvfilein[ ]import pandas as pd the file has no headers naming the columnsso we pass header=none and provide the column names explicitly in "namesdata pd read_csv"/home/andy/datasets/adult data"header=noneindex_col=falsenames=['age''workclass''fnlwgt''education''education-num''marital-status''occupation''relationship''race''gender''capital-gain''capital-loss''hours-per-week''native-country''income']for illustration purposeswe only select some of the columns data data[['age''workclass''education''gender''hours-per-week''occupation''income']ipython display allows nice output formatting within the jupyter notebook display(data head()table - shows the result table - the first five rows of the adult dataset age workclass state-gov education gender hours-per-week occupation bachelors male adm-clerical income <= self-emp-not-inc bachelors male exec-managerial private hs-grad male handlers-cleaners <= private th male handlers-cleaners <= private bachelors female prof-specialty <= <= checking string-encoded categorical data after reading dataset like thisit is often good to first check if column actually contains meaningful categorical data when working with data that was input by humans (sayusers on website)there might not be fixed set of categoriesand differences in spelling and capitalization might require preprocessing for exampleit might be that some people specified gender as "maleand some as "man,and we representing data and engineering features