def test_pivot(self): df = pivot(np.array([1, 2, 3, 4, 5]), np.array(['a', 'b', 'c', 'd', 'e']), np.array([1, 2, 3, 5, 4.])) self.assertEqual(df['a'][1], 1) self.assertEqual(df['b'][2], 2) self.assertEqual(df['c'][3], 3) self.assertEqual(df['d'][4], 5) self.assertEqual(df['e'][5], 4) # weird overlap df = pivot(np.array([1, 2, 3, 4, 4]), np.array(['a', 'a', 'a', 'a', 'a']), np.array([1, 2, 3, 5, 4]))
def test_pivot(self): df = pivot(np.array([1, 2, 3, 4, 5]), np.array(['a', 'b', 'c', 'd', 'e']), np.array([1, 2, 3, 5, 4.])) self.assertEqual(df['a'][1], 1) self.assertEqual(df['b'][2], 2) self.assertEqual(df['c'][3], 3) self.assertEqual(df['d'][4], 5) self.assertEqual(df['e'][5], 4) # weird overlap, TODO: test? a, b, c = (np.array([1, 2, 3, 4, 4]), np.array(['a', 'a', 'a', 'a', 'a']), np.array([1, 2, 3, 5, 4])) df = pivot(a, b, c) expected = panelmod._slow_pivot(a, b, c) assert_frame_equal(df, expected) # corner case, empty df = pivot(np.array([]), np.array([]), np.array([]))
def pivot_query(sql, rows, columns, values, con): """ Returns DataFrame with columns corresponding to unique Item entries in the requested SQL query. Parameters ---------- sql: string SQL query to be executed con: SQLConnection """ data = frame_query(sql, con) data = dict([(key.lower(), values) for key, values in data.iteritems()]) pivoted = pivot(data[rows], data[columns], data[values]) return pivoted