old_contents: import pandas as pd
  import numpy as np
  
  
  df = pd.read_csv("data/train.csv")
  # df['Deck'] = df[~df['Cabin'].isnull()]['Cabin'].str[0]
  df[['Deck', 'CabinNumber']] = df['Cabin'].str.extract('(\w)(\d+)')
  df['Title'] = df['Name'].apply(lambda x: x.split(',')[1].split('.')[0].strip())
  df['FamSize'] = df['Parch'] + df['SibSp']
  df[['DeckA', 'DeckB', 'DeckC', 'DeckD', 'DeckE', 'DeckF', 'DeckG']] = df['Deck'].str.get_dummies()
  df = pd.concat([df, df['Title'].str.get_dummies()], axis=1)
  
  
new_contents: import pandas as pd
  import numpy as np
  
  
  df = pd.read_csv("data/train.csv")
  # df['Deck'] = df[~df['Cabin'].isnull()]['Cabin'].str[0]
  df['Title'] = df['Name'].apply(lambda x: x.split(',')[1].split('.')[0].strip())
  df['FamSize'] = df['Parch'] + df['SibSp']
  
  decks_df = df['Cabin'].str.extract('(?P<Deck>\w)(?P<CabinNumber>\d+)')
  deck_dummies = pd.get_dummies(df['Deck'], prefix='Deck')
  title_dummies = pd.get_dummies(df['Title'])
  gender_dummies = pd.get_dummies(df['Sex'])
  class_dummies = pd.get_dummies(df['Pclass'], prefix='Class')
  
  # saving to variables and using .concat() once seems to be much faster
  df = pd.concat([df, decks_df, deck_dummies, title_dummies, gender_dummies, class_dummies], axis=1)
  
subject: use more pd.get_dummies() and use .concat() only once