I want to convert a particular categorical variable into dummy variables using pd.get_dummies() for both test and train data so instead of doing it for both separately, I used a for loop. However, the following code does not work and .head() returns the same dataset.
combine = [train_data, test_data]
for dataset in combine:
dummy_col = pd.get_dummies(dataset['targeted_sex'])
dataset = pd.concat([dataset, dummy_col], axis = 1)
dataset.drop('targeted_sex', axis = 1, inplace = True)
train_data.head() # does not change
Even if I use an iterator which traverses the index like this, it still doesn't work.
for i in range(len(combine)):
Can I get some help? Also, Pandas get_dummies() doesn't provide an inplace option.