@@ -3042,40 +3042,57 @@ any pickled pandas object (or any other pickled object) from file:
3042
3042
See `this question <http://stackoverflow.com/questions/20444593/pandas-compiled-from-source-default-pickle-behavior-changed >`__
3043
3043
for a detailed explanation.
3044
3044
3045
- .. note ::
3046
-
3047
- These methods were previously ``pd.save `` and ``pd.load ``, prior to 0.12.0, and are now deprecated.
3048
-
3049
3045
.. _io.pickle.compression :
3050
3046
3051
- Read/Write compressed pickle files
3052
- ''''''''''''''
3047
+ Compressed pickle files
3048
+ '''''''''''''''''''''''
3053
3049
3054
3050
.. versionadded :: 0.20.0
3055
3051
3056
3052
:func: `read_pickle `, :meth: `DataFame.to_pickle ` and :meth: `Series.to_pickle ` can read
3057
- and write compressed pickle files. Compression types of ``gzip ``, ``bz2 ``, ``xz `` supports
3058
- both read and write. ` `zip `` file supports read only and must contain only one data file
3053
+ and write compressed pickle files. The compression types of ``gzip ``, ``bz2 ``, ``xz `` are supported for reading and writing.
3054
+ `zip`` file supports read only and must contain only one data file
3059
3055
to be read in.
3060
- Compression type can be an explicitely parameter or be inferred from the file extension.
3056
+
3057
+ The compression type can be an explicit parameter or be inferred from the file extension.
3061
3058
If 'infer', then use ``gzip ``, ``bz2 ``, ``zip ``, or ``xz `` if filename ends in ``'.gz' ``, ``'.bz2' ``, ``'.zip' ``, or
3062
3059
``'.xz' ``, respectively.
3063
3060
3064
3061
.. ipython :: python
3065
3062
3066
3063
df = pd.DataFrame({
3067
3064
' A' : np.random.randn(1000 ),
3068
- ' B' : np.random.randn(1000 ),
3069
- ' C' : np.random.randn(1000 )})
3070
- df.to_pickle(" data.pkl.compress" , compression = " gzip" ) # explicit compression type
3071
- df.to_pickle(" data.pkl.xz" , compression = " infer" ) # infer compression type from extension
3072
- df.to_pickle(" data.pkl.gz" ) # default, using "infer"
3073
- df[" A" ].to_pickle(" s1.pkl.bz2" )
3065
+ ' B' : ' foo' ,
3066
+ ' C' : pd.date_range(' 20130101' , periods = 1000 , freq = ' s' )})
3067
+ df
3068
+
3069
+ Using an explicit compression type
3070
+
3071
+ .. ipython :: python
3074
3072
3075
- df = pd.read_pickle(" data.pkl.compress" , compression = " gzip" )
3076
- df = pd.read_pickle(" data.pkl.xz" , compression = " infer" )
3077
- df = pd.read_pickle(" data.pkl.gz" )
3078
- s = pd.read_pickle(" s1.pkl.bz2" )
3073
+ df.to_pickle(" data.pkl.compress" , compression = " gzip" )
3074
+ rt = pd.read_pickle(" data.pkl.compress" , compression = " gzip" )
3075
+ rt
3076
+
3077
+ Inferring compression type from the extension
3078
+
3079
+ .. ipython :: python
3080
+
3081
+ df.to_pickle(" data.pkl.xz" , compression = " infer" )
3082
+ rt = pd.read_pickle(" data.pkl.xz" , compression = " infer" )
3083
+ rt
3084
+
3085
+ The default is to 'infer
3086
+
3087
+ .. ipython :: python
3088
+
3089
+ df.to_pickle(" data.pkl.gz" )
3090
+ rt = pd.read_pickle(" data.pkl.gz" )
3091
+ rt
3092
+
3093
+ df[" A" ].to_pickle(" s1.pkl.bz2" )
3094
+ rt = pd.read_pickle(" s1.pkl.bz2" )
3095
+ rt
3079
3096
3080
3097
.. ipython :: python
3081
3098
:suppress:
0 commit comments