pydata/pandas — pull request #9117 by sinhrks (2014-12-20 21:55:54+00:00)
Title: (WIP) ENH: get_dummies can accept value and na_value kw

Closes #8028. It is still under work, but want to clarify a point. Currently it works as:

```
s = pd.Series(['A', 'B', 'A', 'C'])
s
# 0 A
# 1 B
# 2 A
# 3 C
# dtype: object

pd.get_dummies(s)
# A B C
# 0 1 0 0
# 1 0 1 0
# 2 1 0 0
# 3 0 0 1

pd.get_dummies(s, value='YES', na_value='NO')
# A B C
# 0 YES NO NO
# 1 NO YES NO
# 2 YES NO NO
# 3 NO NO YES

pd.get_dummies(s, value={'A': 'X', 'B': 'Y', 'C': 'Z'})
# A B C
# 0 X 0 0
# 1 0 Y 0
# 2 X 0 0
# 3 0 0 Z
```

And what I'm concerning is cases for list-likes.

```
# This is natural and compat with replace, because the number of the hole will be the same number as list (one hole in each column).
pd.get_dummies(s, value=['A', 'B', 'A', 'C'])
# A B C
# 0 A 0 0
# 1 0 B 0
# 2 A 0 0
# 3 0 0 C

# When we specify na_value and make it compat with replace, behavior should be:
pd.get_dummies(s, na_value=['A', 'B', 'A', 'C'])
# A B C
0 1 A B
1 A 1 C
2 1 A B
3 A C 1

# Or it needs different broadcasting rule?
pd.get_dummies(s, na_value=['A', 'B', 'A', 'C'])
# A B C
# 0 1 A A
# 1 B 1 B
# 2 1 A A
# 3 C C 1
```