-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH add drop_na argument to pivot_table
- Loading branch information
Showing
5 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import nose | ||
import unittest | ||
|
||
import numpy as np | ||
from numpy.testing import assert_equal | ||
|
||
from pandas.tools.util import cartesian_product | ||
|
||
class TestCartesianProduct(unittest.TestCase): | ||
|
||
def test_simple(self): | ||
x, y = list('ABC'), [1, 22] | ||
result = cartesian_product([x, y]) | ||
expected = [np.array(['A', 'A', 'B', 'B', 'C', 'C']), | ||
np.array([ 1, 22, 1, 22, 1, 22])] | ||
assert_equal(result, expected) | ||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
from pandas.core.index import Index | ||
import numpy as np | ||
|
||
def match(needles, haystack): | ||
haystack = Index(haystack) | ||
needles = Index(needles) | ||
return haystack.get_indexer(needles) | ||
return haystack.get_indexer(needles) | ||
|
||
def cartesian_product(X): | ||
''' | ||
Numpy version of itertools.product or pandas.util.compat.product. | ||
Sometimes faster (for large inputs)... | ||
Examples | ||
-------- | ||
>>> cartesian_product([list('ABC'), [1, 2]]) | ||
[array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='|S1'), | ||
array([1, 2, 1, 2, 1, 2])] | ||
''' | ||
lenX = map(len, X) | ||
cumprodX = np.cumproduct(lenX) | ||
a = np.insert(cumprodX, 0, 1) | ||
b = a[-1] / a[1:] | ||
return [np.tile(np.repeat(x, b[i]), | ||
np.product(a[i])) | ||
for i, x in enumerate(X)] | ||
|