title: Hot Deck Imputation in Python
body: <p>I have been trying to find Python code that would allow me to replace missing values in a dataframe's column. The focus of my analysis is in biostatistics so I am not comfortable with replacing values using means/medians/modes. I would like to apply the <a href="https://en.wikipedia.org/wiki/Imputation_(statistics)#Hot-deck" rel="nofollow noreferrer">"Hot Deck Imputation"</a> method. </p>
  
  <p>I cannot find any Python functions or packages online that takes the column of a dataframe and fills missing values with the "Hot Deck Imputation" method. </p>
  
  <p>I did, however, see this <a href="https://github.com/tarikbir/missing_data_imputation" rel="nofollow noreferrer">GitHub project</a> and <em>did not</em> find it useful.</p>
  
  <p>The following is an example of some of my data (assume this is a pandas dataframe):</p>
  
  <pre><code>| age | sex | bmi  | anesthesia score | pain level |
  |-----|-----|------|------------------|------------|
  | 78  | 1   | 40.7 | 3                | 0          |
  | 55  | 1   | 25.3 | 3                | 0          |
  | 52  | 0   | 25.4 | 3                | 0          |
  | 77  | 1   | 44.9 | 3                | 3          |
  | 71  | 1   | 26.3 | 3                | 0          |
  | 39  | 0   | 28.2 | 2                | 0          |
  | 82  | 1   | 27   | 2                | 1          |
  | 70  | 1   | 37.9 | 3                | 0          |
  | 71  | 1   | NA   | 3                | 1          |
  | 53  | 0   | 24.5 | 2                | NA         |
  | 68  | 0   | 34.7 | 3                | 0          |
  | 57  | 0   | 30.7 | 2                | 0          |
  | 40  | 1   | 22.4 | 2                | 0          |
  | 73  | 1   | 34.2 | 2                | 0          |
  | 66  | 1   | NA   | 3                | 1          |
  | 55  | 1   | 42.6 | NA               | NA         |
  | 53  | 0   | 37.5 | 3                | 3          |
  | 65  | 0   | 31.6 | 2                | 2          |
  | 36  | 0   | 29.6 | 1                | 0          |
  | 60  | 0   | 25.7 | 2                | NA         |
  | 70  | 1   | 30   | NA               | NA         |
  | 66  | 1   | 28.3 | 2                | 0          |
  | 63  | 1   | 29.4 | 3                | 2          |
  | 70  | 1   | 36   | 3                | 2          |
  </code></pre>
  
  <p>I would like to apply a Python function that would allow me to input a column as a parameter and return the column with the missing values replaced with imputed values using the "Hot Deck Imputation" method. </p>
  
  <p>I am using this for the purpose of statistical modeling with models such as linear and logistic regression using <code>Statsmodels.api</code>. I am not using this for Machine Learning.</p>
  
  <p>Any help would be much appreciated!</p>