Beispiel #1
0
    def test_pivot(self):
        from pandas.core.reshape import _slow_pivot

        df = pivot(np.array([1, 2, 3, 4, 5]), np.array(["a", "b", "c", "d", "e"]), np.array([1, 2, 3, 5, 4.0]))
        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.0, 2.0, 3.0, 4.0, 5.0]))
        df = pivot(a, b, c)
        expected = _slow_pivot(a, b, c)
        assert_frame_equal(df, expected)

        # corner case, empty
        df = pivot(np.array([]), np.array([]), np.array([]))
Beispiel #2
0
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
Beispiel #3
0
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