当前位置: 首页>>代码示例>>Python>>正文


Python pandas.to_pickle方法代码示例

本文整理汇总了Python中pandas.to_pickle方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.to_pickle方法的具体用法?Python pandas.to_pickle怎么用?Python pandas.to_pickle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.to_pickle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_explicit

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_write_explicit(self, compression, get_random_path):
        base = get_random_path
        path1 = base + ".compressed"
        path2 = base + ".raw"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to compressed file
            df.to_pickle(p1, compression=compression)

            # decompress
            with tm.decompress_file(p1, compression=compression) as f:
                with open(p2, "wb") as fh:
                    fh.write(f.read())

            # read decompressed file
            df2 = pd.read_pickle(p2, compression=None)

            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_pickle.py

示例2: test_read_explicit

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_read_explicit(self, compression, get_random_path):
        base = get_random_path
        path1 = base + ".raw"
        path2 = base + ".compressed"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to uncompressed file
            df.to_pickle(p1, compression=None)

            # compress
            self.compress_file(p1, p2, compression=compression)

            # read compressed file
            df2 = pd.read_pickle(p2, compression=compression)

            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_pickle.py

示例3: round_trip_pickle

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def round_trip_pickle(obj, path=None):
    """
    Pickle an object and then read it again.

    Parameters
    ----------
    obj : pandas object
        The object to pickle and then re-read.
    path : str, default None
        The path where the pickled object is written and then read.

    Returns
    -------
    round_trip_pickled_object : pandas object
        The original object that was pickled and then re-read.
    """

    if path is None:
        path = u('__{random_bytes}__.pickle'.format(random_bytes=rands(10)))
    with ensure_clean(path) as path:
        pd.to_pickle(obj, path)
        return pd.read_pickle(path) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:testing.py

示例4: _handle_exception

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def _handle_exception(statements, database, exception_info):
    directory = Path(str(database.bind.url)[10:])
    if not directory.is_dir():
        directory = Path(".")
    directory = directory.resolve()

    for stat in statements:
        if isinstance(stat, (sqlalchemy.sql.dml.Insert, sqlalchemy.sql.dml.Update)):
            values = stat.compile().params
            timestamp = dt.datetime.now().strftime("%Y%m%d-%H%M%S-%f")
            filename = f"{stat.table.name}_{timestamp}.pickle"
            pd.to_pickle(values, directory / filename)

    warnings.warn(
        f"Unable to write to database. The data was saved in {directory} instead. The "
        f"traceback was:\n\n{exception_info}"
    ) 
开发者ID:OpenSourceEconomics,项目名称:estimagic,代码行数:19,代码来源:update_database.py

示例5: test_write_explicit

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_write_explicit(self, compression, get_random_path):
        # issue 11666
        if compression == 'xz':
            tm._skip_if_no_lzma()

        base = get_random_path
        path1 = base + ".compressed"
        path2 = base + ".raw"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to compressed file
            df.to_pickle(p1, compression=compression)

            # decompress
            self.decompress_file(p1, p2, compression=compression)

            # read decompressed file
            df2 = pd.read_pickle(p2, compression=None)

            tm.assert_frame_equal(df, df2) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:24,代码来源:test_pickle.py

示例6: test_read_explicit

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_read_explicit(self, compression, get_random_path):
        # issue 11666
        if compression == 'xz':
            tm._skip_if_no_lzma()

        base = get_random_path
        path1 = base + ".raw"
        path2 = base + ".compressed"

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to uncompressed file
            df.to_pickle(p1, compression=None)

            # compress
            self.compress_file(p1, p2, compression=compression)

            # read compressed file
            df2 = pd.read_pickle(p2, compression=compression)

            tm.assert_frame_equal(df, df2) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:24,代码来源:test_pickle.py

示例7: test_to_pickle

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_to_pickle():
    modin_df = create_test_modin_dataframe()
    pandas_df = create_test_pandas_dataframe()

    TEST_PICKLE_DF_FILENAME = "test_df.pkl"
    TEST_PICKLE_pandas_FILENAME = "test_pandas.pkl"

    modin_df.to_pickle(TEST_PICKLE_DF_FILENAME)
    pandas_df.to_pickle(TEST_PICKLE_pandas_FILENAME)

    assert assert_files_eq(TEST_PICKLE_DF_FILENAME, TEST_PICKLE_pandas_FILENAME)

    teardown_test_file(TEST_PICKLE_pandas_FILENAME)
    teardown_test_file(TEST_PICKLE_DF_FILENAME)

    pd.to_pickle(modin_df, TEST_PICKLE_DF_FILENAME)
    pandas.to_pickle(pandas_df, TEST_PICKLE_pandas_FILENAME)

    assert assert_files_eq(TEST_PICKLE_DF_FILENAME, TEST_PICKLE_pandas_FILENAME)

    teardown_test_file(TEST_PICKLE_pandas_FILENAME)
    teardown_test_file(TEST_PICKLE_DF_FILENAME) 
开发者ID:modin-project,项目名称:modin,代码行数:24,代码来源:test_io.py

示例8: test_pickle_path_pathlib

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_pickle_path_pathlib():
    df = tm.makeDataFrame()
    result = tm.round_trip_pathlib(df.to_pickle, pd.read_pickle)
    tm.assert_frame_equal(df, result) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_pickle.py

示例9: test_pickle_path_localpath

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_pickle_path_localpath():
    df = tm.makeDataFrame()
    result = tm.round_trip_localpath(df.to_pickle, pd.read_pickle)
    tm.assert_frame_equal(df, result)


# ---------------------
# test pickle compression
# --------------------- 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_pickle.py

示例10: test_write_explicit_bad

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_write_explicit_bad(self, compression, get_random_path):
        with pytest.raises(ValueError, match="Unrecognized compression type"):
            with tm.ensure_clean(get_random_path) as path:
                df = tm.makeDataFrame()
                df.to_pickle(path, compression=compression) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_pickle.py

示例11: test_read_infer

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_read_infer(self, ext, get_random_path):
        base = get_random_path
        path1 = base + ".raw"
        path2 = base + ext
        compression = None
        for c in self._compression_to_extension:
            if self._compression_to_extension[c] == ext:
                compression = c
                break

        with tm.ensure_clean(path1) as p1, tm.ensure_clean(path2) as p2:
            df = tm.makeDataFrame()

            # write to uncompressed file
            df.to_pickle(p1, compression=None)

            # compress
            self.compress_file(p1, p2, compression=compression)

            # read compressed file by inferred compression method
            df2 = pd.read_pickle(p2)

            tm.assert_frame_equal(df, df2)


# ---------------------
# test pickle compression
# --------------------- 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:test_pickle.py

示例12: test_read

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_read(self, protocol, get_random_path):
        with tm.ensure_clean(get_random_path) as path:
            df = tm.makeDataFrame()
            df.to_pickle(path, protocol=protocol)
            df2 = pd.read_pickle(path)
            tm.assert_frame_equal(df, df2) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_pickle.py

示例13: test_read_bad_versions

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def test_read_bad_versions(self, protocol, get_random_path):
        # For Python 2, HIGHEST_PROTOCOL should be 2.
        msg = ("pickle protocol {protocol} asked for; the highest available "
               "protocol is 2").format(protocol=protocol)
        with pytest.raises(ValueError, match=msg):
            with tm.ensure_clean(get_random_path) as path:
                df = tm.makeDataFrame()
                df.to_pickle(path, protocol=protocol) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_pickle.py

示例14: serialize

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def serialize(cls, formatted_data, fh):
        # compat: if pandas is old, to_pickle does not accept file handles
        if LooseVersion(pandas.__version__) <= LooseVersion('0.20.3'):
            fh.close()
            fh = fh.name
        return pandas.to_pickle(formatted_data, fh, compression=None) 
开发者ID:airbnb,项目名称:omniduct,代码行数:8,代码来源:_serializers.py

示例15: create_context_graph

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_pickle [as 别名]
def create_context_graph(self, max_num_layers, workers=1, verbose=0,):

        pair_distances = self._compute_structural_distance(
            max_num_layers, workers, verbose,)
        layers_adj, layers_distances = self._get_layer_rep(pair_distances)
        pd.to_pickle(layers_adj, self.temp_path + 'layers_adj.pkl')

        layers_accept, layers_alias = self._get_transition_probs(
            layers_adj, layers_distances)
        pd.to_pickle(layers_alias, self.temp_path + 'layers_alias.pkl')
        pd.to_pickle(layers_accept, self.temp_path + 'layers_accept.pkl') 
开发者ID:shenweichen,项目名称:GraphEmbedding,代码行数:13,代码来源:struc2vec.py


注:本文中的pandas.to_pickle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。