pydata/pandas — pull request #4458 by hayd (2013-08-04 17:32:01+00:00)
Title: Get dummies

fixes 4446, 4444

Added new functionality dummy_na (thoughts?), it's doing slightly different to a possible dropna argument, which I haven't included (and can be achieved using `pd.get_dummies(s.dropna()`).

Example:

```
In [3]: s = ['a', 'b', np.nan]

In [4]: pd.get_dummies(s)
Out[4]:
a b
0 1 0
1 0 1
2 0 0

In [5]: pd.get_dummies(s, dummy_na=True)
Out[5]:
a b NaN
0 1 0 0
1 0 1 0
2 0 0 1

In [6]: pd.get_dummies(pd.Series(s).dropna()) # different to this
Out[6]:
a b
0 1 0
1 0 1
```

Note: atm there is a (strange) test Failure with above example, not quite sure what's going on:

```
res_na = get_dummies(s, dummy_na=True)
exp_na = DataFrame({nan: {0: 0.0, 1: 0.0, 2: 1.0},
'a': {0: 1.0, 1: 0.0, 2: 0.0},
'b': {0: 0.0, 1: 1.0, 2: 0.0}}).iloc[:, [1, 2, 0]] # need to reorder cols
assert_frame_equal(res_na, exp_na)

-> assert(left.columns.equals(right.columns))
(Pdb) left
a b NaN
0 1 0 0
1 0 1 0
2 0 0 1
(Pdb) right
a b NaN
0 1 0 0
1 0 1 0
2 0 0 1
```