コード例 #1
0
ファイル: test_panel.py プロジェクト: willgrass/pandas
    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]))
コード例 #2
0
ファイル: test_panel.py プロジェクト: davidandrzej/pandas
    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([]))
コード例 #3
0
ファイル: sql.py プロジェクト: jlsandell/pandas
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
コード例 #4
0
ファイル: sql.py プロジェクト: choketsu/pandas
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