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


Python DataFrame.copy方法代碼示例

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


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

示例1: test_dates_invalid_column

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def test_dates_invalid_column(self):
        original = DataFrame([datetime(2006, 11, 19, 23, 13, 20)])
        original.index.name = "index"
        with tm.ensure_clean() as path:
            with tm.assert_produces_warning(InvalidColumnName):
                original.to_stata(path, {0: "tc"})

            written_and_read_again = self.read_dta(path)
            modified = original.copy()
            modified.columns = ["_0"]
            tm.assert_frame_equal(written_and_read_again.set_index("index"), modified)
開發者ID:kleingeist,項目名稱:pandas,代碼行數:13,代碼來源:test_stata.py

示例2: test_dates_invalid_column

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def test_dates_invalid_column(self):
        original = DataFrame([datetime(2006, 11, 19, 23, 13, 20)])
        original.index.name = 'index'
        with tm.ensure_clean() as path:
            with warnings.catch_warnings(record=True) as w:
                tm.assert_produces_warning(original.to_stata(path, {0: 'tc'}),
                                           InvalidColumnName)
            tm.assert_equal(len(w), 1)

            written_and_read_again = self.read_dta(path)
            modified = original.copy()
            modified.columns = ['_0']
            tm.assert_frame_equal(written_and_read_again.set_index('index'),
                                  modified)
開發者ID:Rusjjus,項目名稱:pandas,代碼行數:16,代碼來源:test_stata.py

示例3: test_large_value_conversion

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def test_large_value_conversion(self):
        s0 = Series([1, 99], dtype=np.int8)
        s1 = Series([1, 127], dtype=np.int8)
        s2 = Series([1, 2 ** 15 - 1], dtype=np.int16)
        s3 = Series([1, 2 ** 63 - 1], dtype=np.int64)
        original = DataFrame({"s0": s0, "s1": s1, "s2": s2, "s3": s3})
        original.index.name = "index"
        with tm.ensure_clean() as path:
            with tm.assert_produces_warning(PossiblePrecisionLoss):
                original.to_stata(path)

            written_and_read_again = self.read_dta(path)
            modified = original.copy()
            modified["s1"] = Series(modified["s1"], dtype=np.int16)
            modified["s2"] = Series(modified["s2"], dtype=np.int32)
            modified["s3"] = Series(modified["s3"], dtype=np.float64)
            tm.assert_frame_equal(written_and_read_again.set_index("index"), modified)
開發者ID:kleingeist,項目名稱:pandas,代碼行數:19,代碼來源:test_stata.py

示例4: test_large_value_conversion

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def test_large_value_conversion(self):
        s0 = Series([1, 99], dtype=np.int8)
        s1 = Series([1, 127], dtype=np.int8)
        s2 = Series([1, 2 ** 15 - 1], dtype=np.int16)
        s3 = Series([1, 2 ** 63 - 1], dtype=np.int64)
        original = DataFrame({'s0': s0, 's1': s1, 's2': s2, 's3': s3})
        original.index.name = 'index'
        with tm.ensure_clean() as path:
            with warnings.catch_warnings(record=True) as w:
                tm.assert_produces_warning(original.to_stata(path),
                                           PossiblePrecisionLoss)
            # should produce a single warning
            tm.assert_equal(len(w), 1)

            written_and_read_again = self.read_dta(path)
            modified = original.copy()
            modified['s1'] = Series(modified['s1'], dtype=np.int16)
            modified['s2'] = Series(modified['s2'], dtype=np.int32)
            modified['s3'] = Series(modified['s3'], dtype=np.float64)
            tm.assert_frame_equal(written_and_read_again.set_index('index'),
                                  modified)
開發者ID:Rusjjus,項目名稱:pandas,代碼行數:23,代碼來源:test_stata.py

示例5: test_bool_uint

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def test_bool_uint(self):
        s0 = Series([0, 1, True], dtype=np.bool)
        s1 = Series([0, 1, 100], dtype=np.uint8)
        s2 = Series([0, 1, 255], dtype=np.uint8)
        s3 = Series([0, 1, 2 ** 15 - 100], dtype=np.uint16)
        s4 = Series([0, 1, 2 ** 16 - 1], dtype=np.uint16)
        s5 = Series([0, 1, 2 ** 31 - 100], dtype=np.uint32)
        s6 = Series([0, 1, 2 ** 32 - 1], dtype=np.uint32)

        original = DataFrame({"s0": s0, "s1": s1, "s2": s2, "s3": s3, "s4": s4, "s5": s5, "s6": s6})
        original.index.name = "index"
        expected = original.copy()
        expected_types = (np.int8, np.int8, np.int16, np.int16, np.int32, np.int32, np.float64)
        for c, t in zip(expected.columns, expected_types):
            expected[c] = expected[c].astype(t)

        with tm.ensure_clean() as path:
            original.to_stata(path)
            written_and_read_again = self.read_dta(path)
            written_and_read_again = written_and_read_again.set_index("index")
            tm.assert_frame_equal(written_and_read_again, expected)
開發者ID:JoergRittinger,項目名稱:pandas,代碼行數:23,代碼來源:test_stata.py

示例6: severDeal

# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import copy [as 別名]
    def severDeal(self):
        datadf = None
        isInit = False
        # 1
        place1 = self.placele1.text()
        if place1 != '':
            place1Arr = [list(p) for p in place1.replace('\n','').replace('\r','').split(' ')]
            place1df = DataFrame(place1Arr, columns=['a','b','c','d'])
            if not isInit:
                datadf = place1df.copy()
                isInit = True
            datadf = pd.merge(datadf, place1df)

        # 2
        place2 = self.placele2.text()
        if place2 != '':
            place2Arr = [list(p) for p in place2.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place2df = DataFrame(place2Arr, columns=['a','b','c','e'])
            if not isInit:
                datadf = place2df
                isInit = True
            datadf = pd.merge(datadf, place2df)

        # 3
        place3 = self.placele3.text()
        if place3 != '':
            place3Arr = [list(p) for p in place3.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place3df = DataFrame(place3Arr, columns=['a','b','c','f'])
            if not isInit:
                datadf = place3df
                isInit = True
            datadf = pd.merge(datadf, place3df)

        # 4
        place4 = self.placele4.text()
        if place4 != '':
            place4Arr = [list(p) for p in place4.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place4df = DataFrame(place4Arr, columns=['a','b','c','g'])
            if not isInit:
                datadf = place4df
                isInit = True
            datadf = pd.merge(datadf, place4df)

        # 5
        place5 = self.placele5.text()
        if place5 != '':
            place5Arr = [list(p) for p in place5.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place5df = DataFrame(place5Arr, columns=['a','b','d','e'])
            if not isInit:
                datadf = place5df
                isInit = True
            datadf = pd.merge(datadf, place5df)

        # 6
        place6 = self.placele6.text()
        if place6 != '':
            place6Arr = [list(p) for p in place6.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place6df = DataFrame(place6Arr, columns=['a','b','d','f'])
            if not isInit:
                datadf = place6df
                isInit = True
            datadf = pd.merge(datadf, place6df)

        # 7
        place7 = self.placele7.text()
        if place7 != '':
            place7Arr = [list(p) for p in place7.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place7df = DataFrame(place7Arr, columns=['a','b','d','g'])
            if not isInit:
                datadf = place7df
                isInit = True
            datadf = pd.merge(datadf, place7df)

        # 8
        place8 = self.placele8.text()
        if place8 != '':
            place8Arr = [list(p) for p in place8.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place8df = DataFrame(place8Arr, columns=['a','b','e','f'])
            if not isInit:
                datadf = place8df
                isInit = True
            datadf = pd.merge(datadf, place8df)

        # 9
        place9 = self.placele9.text()
        if place9 != '':
            place9Arr = [list(p) for p in place9.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place9df = DataFrame(place9Arr, columns=['a','b','e','g'])
            if not isInit:
                datadf = place9df
                isInit = True
            datadf = pd.merge(datadf, place9df)

        # 10
        place10 = self.placele10.text()
        if place10 != '':
            place10Arr = [list(p) for p in place10.replace('\n','').replace('\r','').replace('  ',' ').split(' ')]
            place10df = DataFrame(place10Arr, columns=['a','b','f','g'])
            if not isInit:
                datadf = place10df
#.........這裏部分代碼省略.........
開發者ID:argen77,項目名稱:vague,代碼行數:103,代碼來源:MainWindow.py


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