當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.SubclassedSeries方法代碼示例

本文整理匯總了Python中pandas.util.testing.SubclassedSeries方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.SubclassedSeries方法的具體用法?Python testing.SubclassedSeries怎麽用?Python testing.SubclassedSeries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.SubclassedSeries方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_subclass_align

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_align(self):
        # GH 12983
        df1 = tm.SubclassedDataFrame({'a': [1, 3, 5],
                                      'b': [1, 3, 5]}, index=list('ACE'))
        df2 = tm.SubclassedDataFrame({'c': [1, 2, 4],
                                      'd': [1, 2, 4]}, index=list('ABD'))

        res1, res2 = df1.align(df2, axis=0)
        exp1 = tm.SubclassedDataFrame({'a': [1, np.nan, 3, np.nan, 5],
                                       'b': [1, np.nan, 3, np.nan, 5]},
                                      index=list('ABCDE'))
        exp2 = tm.SubclassedDataFrame({'c': [1, 2, np.nan, 4, np.nan],
                                       'd': [1, 2, np.nan, 4, np.nan]},
                                      index=list('ABCDE'))
        assert isinstance(res1, tm.SubclassedDataFrame)
        tm.assert_frame_equal(res1, exp1)
        assert isinstance(res2, tm.SubclassedDataFrame)
        tm.assert_frame_equal(res2, exp2)

        res1, res2 = df1.a.align(df2.c)
        assert isinstance(res1, tm.SubclassedSeries)
        tm.assert_series_equal(res1, exp1.a)
        assert isinstance(res2, tm.SubclassedSeries)
        tm.assert_series_equal(res2, exp2.c) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_subclass.py

示例2: test_indexing_sliced

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_indexing_sliced(self):
        s = tm.SubclassedSeries([1, 2, 3, 4], index=list('abcd'))
        res = s.loc[['a', 'b']]
        exp = tm.SubclassedSeries([1, 2], index=list('ab'))
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = s.iloc[[2, 3]]
        exp = tm.SubclassedSeries([3, 4], index=list('cd'))
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = s.loc[['a', 'b']]
        exp = tm.SubclassedSeries([1, 2], index=list('ab'))
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:18,代碼來源:test_subclass.py

示例3: test_indexing_sliced

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_indexing_sliced(self):
        s = tm.SubclassedSeries([1, 2, 3, 4], index=list('abcd'))
        res = s.loc[['a', 'b']]
        exp = tm.SubclassedSeries([1, 2], index=list('ab'))
        tm.assert_series_equal(res, exp)

        res = s.iloc[[2, 3]]
        exp = tm.SubclassedSeries([3, 4], index=list('cd'))
        tm.assert_series_equal(res, exp)

        res = s.loc[['a', 'b']]
        exp = tm.SubclassedSeries([1, 2], index=list('ab'))
        tm.assert_series_equal(res, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_subclass.py

示例4: test_to_frame

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_to_frame(self):
        s = tm.SubclassedSeries([1, 2, 3, 4], index=list('abcd'), name='xxx')
        res = s.to_frame()
        exp = tm.SubclassedDataFrame({'xxx': [1, 2, 3, 4]}, index=list('abcd'))
        tm.assert_frame_equal(res, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_subclass.py

示例5: test_subclass_unstack

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_unstack(self):
        # GH 15564
        s = tm.SubclassedSeries(
            [1, 2, 3, 4], index=[list('aabb'), list('xyxy')])

        res = s.unstack()
        exp = tm.SubclassedDataFrame(
            {'x': [1, 3], 'y': [2, 4]}, index=['a', 'b'])

        tm.assert_frame_equal(res, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_subclass.py

示例6: test_indexing_sliced

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_indexing_sliced(self):
        # GH 11559
        df = tm.SubclassedDataFrame({'X': [1, 2, 3],
                                     'Y': [4, 5, 6],
                                     'Z': [7, 8, 9]},
                                    index=['a', 'b', 'c'])
        res = df.loc[:, 'X']
        exp = tm.SubclassedSeries([1, 2, 3], index=list('abc'), name='X')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = df.iloc[:, 1]
        exp = tm.SubclassedSeries([4, 5, 6], index=list('abc'), name='Y')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = df.loc[:, 'Z']
        exp = tm.SubclassedSeries([7, 8, 9], index=list('abc'), name='Z')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = df.loc['a', :]
        exp = tm.SubclassedSeries([1, 4, 7], index=list('XYZ'), name='a')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = df.iloc[1, :]
        exp = tm.SubclassedSeries([2, 5, 8], index=list('XYZ'), name='b')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries)

        res = df.loc['c', :]
        exp = tm.SubclassedSeries([3, 6, 9], index=list('XYZ'), name='c')
        tm.assert_series_equal(res, exp)
        assert isinstance(res, tm.SubclassedSeries) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:37,代碼來源:test_subclass.py

示例7: test_subclass_iterrows

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_iterrows(self):
        # GH 13977
        df = tm.SubclassedDataFrame({'a': [1]})
        for i, row in df.iterrows():
            assert isinstance(row, tm.SubclassedSeries)
            tm.assert_series_equal(row, df.loc[i]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_subclass.py

示例8: test_subclass_stack

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_stack(self):
        # GH 15564
        df = tm.SubclassedDataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                                    index=['a', 'b', 'c'],
                                    columns=['X', 'Y', 'Z'])

        res = df.stack()
        exp = tm.SubclassedSeries(
            [1, 2, 3, 4, 5, 6, 7, 8, 9],
            index=[list('aaabbbccc'), list('XYZXYZXYZ')])

        tm.assert_series_equal(res, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_subclass.py

示例9: test_subclass_unstack

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_unstack(self):
        # GH 15564
        df = tm.SubclassedDataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                                    index=['a', 'b', 'c'],
                                    columns=['X', 'Y', 'Z'])

        res = df.unstack()
        exp = tm.SubclassedSeries(
            [1, 4, 7, 2, 5, 8, 3, 6, 9],
            index=[list('XXXYYYZZZ'), list('abcabcabc')])

        tm.assert_series_equal(res, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_subclass.py

示例10: test_to_frame

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_to_frame(self):
        s = tm.SubclassedSeries([1, 2, 3, 4], index=list('abcd'), name='xxx')
        res = s.to_frame()
        exp = tm.SubclassedDataFrame({'xxx': [1, 2, 3, 4]}, index=list('abcd'))
        tm.assert_frame_equal(res, exp)
        assert isinstance(res, tm.SubclassedDataFrame) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:8,代碼來源:test_subclass.py

示例11: test_subclass_align_combinations

# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import SubclassedSeries [as 別名]
def test_subclass_align_combinations(self):
        # GH 12983
        df = tm.SubclassedDataFrame({'a': [1, 3, 5],
                                     'b': [1, 3, 5]}, index=list('ACE'))
        s = tm.SubclassedSeries([1, 2, 4], index=list('ABD'), name='x')

        # frame + series
        res1, res2 = df.align(s, axis=0)
        exp1 = pd.DataFrame({'a': [1, np.nan, 3, np.nan, 5],
                             'b': [1, np.nan, 3, np.nan, 5]},
                            index=list('ABCDE'))
        # name is lost when
        exp2 = pd.Series([1, 2, np.nan, 4, np.nan],
                         index=list('ABCDE'), name='x')

        assert isinstance(res1, tm.SubclassedDataFrame)
        tm.assert_frame_equal(res1, exp1)
        assert isinstance(res2, tm.SubclassedSeries)
        tm.assert_series_equal(res2, exp2)

        # series + frame
        res1, res2 = s.align(df)
        assert isinstance(res1, tm.SubclassedSeries)
        tm.assert_series_equal(res1, exp2)
        assert isinstance(res2, tm.SubclassedDataFrame)
        tm.assert_frame_equal(res2, exp1) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:28,代碼來源:test_subclass.py


注:本文中的pandas.util.testing.SubclassedSeries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。