Feature-Request: Allow user defined categories in get_dummies()
State: closed

- [ ] closes #22078
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Allow user to provide his own set of labels for `get_dummies()`. Useful if one has multiple dataframes and not all categories are present in some of them.
Just wanted to get some general feedback if this is a good idea.
Will do docs, tests, etc. if this is considered a useful feature. Below some examples on how it works.

```python
In [26]: df
Out[26]: 
  var_1  var_2  y
0     a      1  1
1     b      1  2
2     c      1  3
3     a      0  4
4     a      0  5

# current state remains unaffected
In [27]: pd.get_dummies(df, columns=['var_1'])
Out[27]: 
   var_2  y  var_1_a  var_1_b  var_1_c
0      1  1        1        0        0
1      1  2        0        1        0
2      1  3        0        0        1
3      0  4        1        0        0
4      0  5        1        0        0

# if categories are provided, use those.
In [28]: pd.get_dummies(df, columns=['var_1'], categories=[['a','c','f','b']])
Out[28]: 
   var_2  y  var_1_a  var_1_c  var_1_f  var_1_b
0      1  1        1        0        0        0
1      1  2        0        0        0        1
2      1  3        0        1        0        0
3      0  4        1        0        0        0
4      0  5        1        0        0        0

# works with multiple columns
In [29]: pd.get_dummies(df, columns=['var_1', 'var_2'], categories=[['a','c','f','b'], [2,1,0]])
Out[29]: 
   y  var_1_a  var_1_c  var_1_f  var_1_b  var_2_2  var_2_1  var_2_0
0  1        1        0        0        0        0        1        0
1  2        0        0        0        1        0        1        0
2  3        0        1        0        0        0        1        0
3  4        1        0        0        0        0        0        1
4  5        1        0        0        0        0        0        1

# None has to be provided if default is wanted (which seems unnecessary, but showing it works)
In [30]: pd.get_dummies(df, columns=['var_1', 'var_2'], categories=[['a','c','f','b'], None])
Out[30]: 
   y  var_1_a  var_1_c  var_1_f  var_1_b  var_2_0  var_2_1
0  1        1        0        0        0        0        1
1  2        0        0        0        1        0        1
2  3        0        1        0        0        0        1
3  4        1        0        0        0        1        0
4  5        1        0        0        0        1        0
```

Labels:
name: Enhancement

Comments:
Hello @abieler! Thanks for updating the PR.





Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 27, 2018 at 07:01 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=h1) Report
> Merging [#22076](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7a2fbce899aad302891ff9a95aeb1bd55efe533a?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22076/graphs/tree.svg?token=eZ4WkYLtcO&height=150&src=pr&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22076      +/-   ##
==========================================
+ Coverage   92.05%   92.05%   +<.01%     
==========================================
  Files         170      170              
  Lines       50708    50710       +2     
==========================================
+ Hits        46677    46679       +2     
  Misses       4031     4031
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.45% <100%> (ø)` | :arrow_up: |
| #single | `42.36% <33.33%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/22076/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `99.78% <100%> (ø)` | :arrow_up: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/22076/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.95% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=footer). Last update [7a2fbce...59711e6](https://codecov.io/gh/pandas-dev/pandas/pull/22076?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@abieler : Thanks for this PR!  We generally prefer that you open an issue before the PR, so that we can actually discuss whether this feature is a good idea or not.

We won't close this PR, but it would be great if you could open an issue and move your reasoning in the PR description to the issue description.
@gfyoung feel free to close the PR if this disrupts the usual workflow of you guys.
> @gfyoung feel free to close the PR if this disrupts the usual workflow of you guys.

@abieler : No need ATM.  As I said above, we'll evaluate the issue and see how best to proceed.
will comment on the issue