I have two files train.csv and test.csv, I am trying to clean the datasets and apply feature engineering on both of them separately. Suppose in train.csv I have a column dummy which consists of only two type of values ('A','B'), but in test.csv that same columns contains three type of values ('A','B','C') the value 'C' is missing in train.csv, so now when I will Hot Encode train.csv using pandas dummy method:
data = pd.get_dummies(data,columns=['dummy'],prefix=['dummy'])
I will end up having different number of columns in train and test datasets. This problem occurs in multiple columns.
train.csv:
-------
|dummy |
--------
|A |
--------
|B |
--------
|A |
--------
|A |
--------
test.csv:
-------
|dummy |
--------
|A |
--------
|B |
--------
|C |
--------
|A |
--------