Table Of Contents

Search

Enter search terms or a module, class or function name.

What’s New

These are new features and improvements of note in each release.

v0.13.0 (October ??, 2013)

This is a major release from 0.12.0 and includes a number of API changes, several new features and enhancements along with a large number of bug fixes.

Highlights include support for a new index type Float64Index, support for new methods of interpolation, updated timedelta operations, and a new string manipulation method extract. Several experimental features are added, including new eval/query methods for expression evaluation, support for msgpack serialization, and an io interface to Google’s BigQuery.

Warning

In 0.13.0 Series has internally been refactored to no longer sub-class ndarray but instead subclass NDFrame, similar to the rest of the pandas containers. This should be a transparent change with only very limited API implications. See Internal Refactoring

API changes

  • read_excel now supports an integer in its sheetname argument giving the index of the sheet to read in (GH4301).

  • Text parser now treats anything that reads like inf (“inf”, “Inf”, “-Inf”, “iNf”, etc.) as infinity. (GH4220, GH4219), affecting read_table, read_csv, etc.

  • pandas now is Python 2/3 compatible without the need for 2to3 thanks to @jtratner. As a result, pandas now uses iterators more extensively. This also led to the introduction of substantive parts of the Benjamin Peterson’s six library into compat. (GH4384, GH4375, GH4372)

  • pandas.util.compat and pandas.util.py3compat have been merged into pandas.compat. pandas.compat now includes many functions allowing 2/3 compatibility. It contains both list and iterator versions of range, filter, map and zip, plus other necessary elements for Python 3 compatibility. lmap, lzip, lrange and lfilter all produce lists instead of iterators, for compatibility with numpy, subscripting and pandas constructors.(GH4384, GH4375, GH4372)

  • Series.get with negative indexers now returns the same as [] (GH4390)

  • Changes to how Index and MultiIndex handle metadata (levels, labels, and names) (GH4039):

    # previously, you would have set levels or labels directly
    index.levels = [[1, 2, 3, 4], [1, 2, 4, 4]]
    
    # now, you use the set_levels or set_labels methods
    index = index.set_levels([[1, 2, 3, 4], [1, 2, 4, 4]])
    
    # similarly, for names, you can rename the object
    # but setting names is not deprecated.
    index = index.set_names(["bob", "cranberry"])
    
    # and all methods take an inplace kwarg - but returns None
    index.set_names(["bob", "cranberry"], inplace=True)
    
  • Infer and downcast dtype if downcast='infer' is passed to fillna/ffill/bfill (GH4604)

  • __nonzero__ for all NDFrame objects, will now raise a ValueError, this reverts back to (GH1073, GH4633) behavior. See gotchas for a more detailed discussion.

    This prevents doing boolean comparision on entire pandas objects, which is inherently ambiguous. These all will raise a ValueError.

    if df:
       ....
    df1 and df2
    s1 and s2
    

    Added the .bool() method to NDFrame objects to facilitate evaluating of single-element boolean Series:

    In [1]: Series([True]).bool()
    True
    
    In [2]: Series([False]).bool()
    False
    
    In [3]: DataFrame([[True]]).bool()
    True
    
    In [4]: DataFrame([[False]]).bool()
    False
    
  • All non-Index NDFrames (Series, DataFrame, Panel, Panel4D, SparsePanel, etc.), now support the entire set of arithmetic operators and arithmetic flex methods (add, sub, mul, etc.). SparsePanel does not support pow or mod with non-scalars. (GH3765)

Prior Version Deprecations/Changes

These were announced changes in 0.12 or prior that are taking effect as of 0.13.0

  • Remove deprecated Factor (GH3650)
  • Remove deprecated set_printoptions/reset_printoptions (GH3046)
  • Remove deprecated _verbose_info (GH3215)
  • Remove deprecated read_clipboard/to_clipboard/ExcelFile/ExcelWriter from pandas.io.parsers (GH3717)
  • default for tupleize_cols is now False for both to_csv and read_csv. Fair warning in 0.12 (GH3604)

Deprecations

Deprecated in 0.13.0

  • deprecated iterkv, which will be removed in a future release (this was an alias of iteritems used to bypass 2to3‘s changes). (GH4384, GH4375, GH4372)

Indexing API Changes

Prior to 0.13, it was impossible to use a label indexer (.loc/.ix) to set a value that was not contained in the index of a particular axis. (GH2578). See more the docs

In the Series case this is effectively an appending operation

In [5]: s = Series([1,2,3])

In [6]: s

0    1
1    2
2    3
dtype: int64

In [7]: s[5] = 5.

In [8]: s

0    1
1    2
2    3
5    5
dtype: float64
In [9]: dfi = DataFrame(np.arange(6).reshape(3,2),
   ...:                 columns=['A','B'])
   ...: 

In [10]: dfi

   A  B
0  0  1
1  2  3
2  4  5

This would previously KeyError

In [11]: dfi.loc[:,'C'] = dfi.loc[:,'A']

In [12]: dfi

   A  B  C
0  0  1  0
1  2  3  2
2  4  5  4

This is like an append operation.

In [13]: dfi.loc[3] = 5

In [14]: dfi

   A  B  C
0  0  1  0
1  2  3  2
2  4  5  4
3  5  5  5

A Panel setting operation on an arbitrary axis aligns the input to the Panel

In [15]: p = pd.Panel(np.arange(16).reshape(2,4,2),
   ....:             items=['Item1','Item2'],
   ....:             major_axis=pd.date_range('2001/1/12',periods=4),
   ....:             minor_axis=['A','B'],dtype='float64')
   ....: 

In [16]: p

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to B

In [17]: p.loc[:,:,'C'] = Series([30,32],index=p.items)

In [18]: p

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 3 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to C

In [19]: p.loc[:,:,'C']

            Item1  Item2
2001-01-12     30     32
2001-01-13     30     32
2001-01-14     30     32
2001-01-15     30     32

Float64Index API Change

  • Added a new index type, Float64Index. This will be automatically created when passing floating values in index creation. This enables a pure label-based slicing paradigm that makes [],ix,loc for scalar indexing and slicing work exactly the same. See the docs, (GH263)

    Construction is by default for floating type values.

    In [20]: index = Index([1.5, 2, 3, 4.5, 5])
    
    In [21]: index
    Float64Index([1.5, 2.0, 3.0, 4.5, 5.0], dtype='object')
    
    In [22]: s = Series(range(5),index=index)
    
    In [23]: s
    
    1.5    0
    2.0    1
    3.0    2
    4.5    3
    5.0    4
    dtype: int64
    

    Scalar selection for [],.ix,.loc will always be label based. An integer will match an equal float index (e.g. 3 is equivalent to 3.0)

    In [24]: s[3]
    2
    
    In [25]: s.ix[3]
    2
    
    In [26]: s.loc[3]
    2
    

    The only positional indexing is via iloc

    In [27]: s.iloc[3]
    3
    

    A scalar index that is not found will raise KeyError

    Slicing is ALWAYS on the values of the index, for [],ix,loc and ALWAYS positional with iloc

    In [28]: s[2:4]
    
    2    1
    3    2
    dtype: int64
    
    In [29]: s.ix[2:4]
    
    2    1
    3    2
    dtype: int64
    
    In [30]: s.loc[2:4]
    
    2    1
    3    2
    dtype: int64
    
    In [31]: s.iloc[2:4]
    
    3.0    2
    4.5    3
    dtype: int64
    

    In float indexes, slicing using floats are allowed

    In [32]: s[2.1:4.6]
    
    3.0    2
    4.5    3
    dtype: int64
    
    In [33]: s.loc[2.1:4.6]
    
    3.0    2
    4.5    3
    dtype: int64
    
  • Indexing on other index types are preserved (and positional fallback for [],ix), with the exception, that floating point slicing on indexes on non Float64Index will now raise a TypeError.

    In [1]: Series(range(5))[3.5]
    TypeError: the label [3.5] is not a proper indexer for this index type (Int64Index)
    
    In [1]: Series(range(5))[3.5:4.5]
    TypeError: the slice start [3.5] is not a proper indexer for this index type (Int64Index)
    

    Using a scalar float indexer will be deprecated in a future version, but is allowed for now.

    In [3]: Series(range(5))[3.0]
    Out[3]: 3
    

HDFStore API Changes

  • Query Format Changes. A much more string-like query format is now supported. See the docs.

    In [34]: path = 'test.h5'
    
    In [35]: dfq = DataFrame(randn(10,4),
       ....:          columns=list('ABCD'),
       ....:          index=date_range('20130101',periods=10))
       ....: 
    
    In [36]: dfq.to_hdf(path,'dfq',format='table',data_columns=True)
    

    Use boolean expressions, with in-line function evaluation.

    In [37]: read_hdf(path,'dfq',
       ....:     where="index>Timestamp('20130104') & columns=['A', 'B']")
       ....: 
    
                       A         B
    2013-01-05  0.049355  0.632633
    2013-01-06 -0.700262 -0.237922
    2013-01-07 -0.419578 -0.159861
    2013-01-08  1.144951 -0.726740
    2013-01-09  0.309259 -0.328860
    2013-01-10  1.785587  1.135875
    

    Use an inline column reference

    In [38]: read_hdf(path,'dfq',
       ....:     where="A>0 or C>0")
       ....: 
    
                       A         B         C         D
    2013-01-01  0.713216 -0.778461 -0.661062  0.862877
    2013-01-02  0.344342  0.149565 -0.626968 -0.875772
    2013-01-03 -0.930687 -0.218983  0.949965 -0.442354
    2013-01-05  0.049355  0.632633 -1.502767 -1.225492
    2013-01-06 -0.700262 -0.237922  0.803216  0.323302
    2013-01-07 -0.419578 -0.159861  0.286230 -0.311358
    2013-01-08  1.144951 -0.726740 -0.178315  0.386127
    2013-01-09  0.309259 -0.328860  0.056344  1.495435
    2013-01-10  1.785587  1.135875  0.699592  0.245373
    
  • the format keyword now replaces the table keyword; allowed values are fixed(f) or table(t) the same defaults as prior < 0.13.0 remain, e.g. put implies fixed format and append imples table format. This default format can be set as an option by setting io.hdf.default_format.

    In [39]: path = 'test.h5'
    
    In [40]: df = DataFrame(randn(10,2))
    
    In [41]: df.to_hdf(path,'df_table',format='table')
    
    In [42]: df.to_hdf(path,'df_table2',append=True)
    
    In [43]: df.to_hdf(path,'df_fixed')
    
    In [44]: with get_store(path) as store:
       ....:    print(store)
       ....: 
    <class 'pandas.io.pytables.HDFStore'>
    File path: test.h5
    /df_fixed             frame        (shape->[10,2])                                       
    /df_table             frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    /df_table2            frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    
  • Significant table writing performance improvements

  • handle a passed Series in table format (GH4330)

  • can now serialize a timedelta64[ns] dtype in a table (GH3577), See the docs.

  • added an is_open property to indicate if the underlying file handle is_open; a closed store will now report ‘CLOSED’ when viewing the store (rather than raising an error) (GH4409)

  • a close of a HDFStore now will close that instance of the HDFStore but will only close the actual file if the ref count (by PyTables) w.r.t. all of the open handles are 0. Essentially you have a local instance of HDFStore referenced by a variable. Once you close it, it will report closed. Other references (to the same file) will continue to operate until they themselves are closed. Performing an action on a closed file will raise ClosedFileError

    In [45]: path = 'test.h5'
    
    In [46]: df = DataFrame(randn(10,2))
    
    In [47]: store1 = HDFStore(path)
    
    In [48]: store2 = HDFStore(path)
    
    In [49]: store1.append('df',df)
    
    In [50]: store2.append('df2',df)
    
    In [51]: store1
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: test.h5
    /df             frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    /df2            frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    
    In [52]: store2
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: test.h5
    /df             frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    /df2            frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    
    In [53]: store1.close()
    
    In [54]: store2
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: test.h5
    /df             frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    /df2            frame_table  (typ->appendable,nrows->10,ncols->2,indexers->[index])
    
    In [55]: store2.close()
    
    In [56]: store2
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: test.h5
    File is CLOSED
    
  • removed the _quiet attribute, replace by a DuplicateWarning if retrieving duplicate rows from a table (GH4367)

  • removed the warn argument from open. Instead a PossibleDataLossError exception will be raised if you try to use mode='w' with an OPEN file handle (GH4367)

  • allow a passed locations array or mask as a where condition (GH4467). See the docs for an example.

  • add the keyword dropna=True to append to change whether ALL nan rows are not written to the store (default is True, ALL nan rows are NOT written), also settable via the option io.hdf.dropna_table (GH4625)

Enhancements

  • read_html now raises a URLError instead of catching and raising a ValueError (GH4303, GH4305)

  • Added a test for read_clipboard() and to_clipboard() (GH4282)

  • Clipboard functionality now works with PySide (GH4282)

  • Added a more informative error message when plot arguments contain overlapping color and style arguments (GH4402)

  • to_dict now takes records as a possible outtype. Returns an array of column-keyed dictionaries. (GH4936)

  • NaN handing in get_dummies (GH4446) with dummy_na

    # previously, nan was erroneously counted as 2 here
    # now it is not counted at all
    In [57]: get_dummies([1, 2, np.nan])
    
       1  2
    0  1  0
    1  0  1
    2  0  0
    
    # unless requested
    In [58]: get_dummies([1, 2, np.nan], dummy_na=True)
    
        1    2   NaN
    0    1    0    0
    1    0    1    0
    2    0    0    1
    
  • timedelta64[ns] operations. See the docs for the docs.

    Warning

    Most of these operations require numpy >= 1.7

    Using the new top-level to_timedelta, you can convert a scalar or array from the standard timedelta format (produced by to_csv) into a timedelta type (np.timedelta64 in nanoseconds).

    In [59]: to_timedelta('1 days 06:05:01.00003')
    
    0   1 days, 06:05:01.000030
    dtype: timedelta64[ns]
    
    In [60]: to_timedelta('15.5us')
    
    0   00:00:00.000016
    dtype: timedelta64[ns]
    
    In [61]: to_timedelta(['1 days 06:05:01.00003','15.5us','nan'])
    
    0   1 days, 06:05:01.000030
    1           00:00:00.000016
    2                       NaT
    dtype: timedelta64[ns]
    
    In [62]: to_timedelta(np.arange(5),unit='s')
    
    0   00:00:00
    1   00:00:01
    2   00:00:02
    3   00:00:03
    4   00:00:04
    dtype: timedelta64[ns]
    
    In [63]: to_timedelta(np.arange(5),unit='d')
    
    0           00:00:00
    1   1 days, 00:00:00
    2   2 days, 00:00:00
    3   3 days, 00:00:00
    4   4 days, 00:00:00
    dtype: timedelta64[ns]
    

    A Series of dtype timedelta64[ns] can now be divided by another timedelta64[ns] object, or astyped to yield a float64 dtyped Series. This is frequency conversion. See the docs for the docs.

    In [64]: from datetime import timedelta
    
    In [65]: td = Series(date_range('20130101',periods=4))-Series(date_range('20121201',periods=4))
    
    In [66]: td[2] += np.timedelta64(timedelta(minutes=5,seconds=3))
    
    In [67]: td[3] = np.nan
    
    In [68]: td
    
    0   31 days, 00:00:00
    1   31 days, 00:00:00
    2   31 days, 00:05:03
    3                 NaT
    dtype: timedelta64[ns]
    
    # to days
    In [69]: td / np.timedelta64(1,'D')
    
    0    31.000000
    1    31.000000
    2    31.003507
    3          NaN
    dtype: float64
    
    In [70]: td.astype('timedelta64[D]')
    
    0    31
    1    31
    2    31
    3   NaN
    dtype: float64
    
    # to seconds
    In [71]: td / np.timedelta64(1,'s')
    
    0    2678400
    1    2678400
    2    2678703
    3        NaN
    dtype: float64
    
    In [72]: td.astype('timedelta64[s]')
    
    0    2678400
    1    2678400
    2    2678703
    3        NaN
    dtype: float64
    

    Dividing or multiplying a timedelta64[ns] Series by an integer or integer Series

    In [73]: td * -1
    
    0   -31 days, 00:00:00
    1   -31 days, 00:00:00
    2   -31 days, 00:05:03
    3                  NaT
    dtype: timedelta64[ns]
    
    In [74]: td * Series([1,2,3,4])
    
    0   31 days, 00:00:00
    1   62 days, 00:00:00
    2   93 days, 00:15:09
    3                 NaT
    dtype: timedelta64[ns]
    

    Absolute DateOffset objects can act equivalenty to timedeltas

    In [75]: from pandas import offsets
    
    In [76]: td + offsets.Minute(5) + offsets.Milli(5)
    
    0   31 days, 00:05:00.005000
    1   31 days, 00:05:00.005000
    2   31 days, 00:10:03.005000
    3                        NaT
    dtype: timedelta64[ns]
    

    Fillna is now supported for timedeltas

    In [77]: td.fillna(0)
    
    0   31 days, 00:00:00
    1   31 days, 00:00:00
    2   31 days, 00:05:03
    3            00:00:00
    dtype: timedelta64[ns]
    
    In [78]: td.fillna(timedelta(days=1,seconds=5))
    
    0   31 days, 00:00:00
    1   31 days, 00:00:00
    2   31 days, 00:05:03
    3    1 days, 00:00:05
    dtype: timedelta64[ns]
    

    You can do numeric reduction operations on timedeltas. Note that these will return a single-element Series.

    In [79]: td.mean()
    
    0   31 days, 00:01:41
    dtype: timedelta64[ns]
    
    In [80]: td.quantile(.1)
    
    0   31 days, 00:00:00
    dtype: timedelta64[ns]
    
  • plot(kind='kde') now accepts the optional parameters bw_method and ind, passed to scipy.stats.gaussian_kde() (for scipy >= 0.11.0) to set the bandwidth, and to gkde.evaluate() to specify the indicies at which it is evaluated, respecttively. See scipy docs. (GH4298)

  • DataFrame constructor now accepts a numpy masked record array (GH3478)

  • The new vectorized string method extract return regular expression matches more conveniently.

    In [81]: Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)')
    
    0      1
    1      2
    2    NaN
    dtype: object
    

    Elements that do not match return NaN. Extracting a regular expression with more than one group returns a DataFrame with one column per group.

    In [82]: Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
    
         0    1
    0    a    1
    1    b    2
    2  NaN  NaN
    

    Elements that do not match return a row of NaN. Thus, a Series of messy strings can be converted into a like-indexed Series or DataFrame of cleaned-up or more useful strings, without necessitating get() to access tuples or re.match objects.

    Named groups like

    In [83]: Series(['a1', 'b2', 'c3']).str.extract(
       ....:         '(?P<letter>[ab])(?P<digit>\d)')
       ....: 
    
      letter digit
    0      a     1
    1      b     2
    2    NaN   NaN
    

    and optional groups can also be used.

    In [84]: Series(['a1', 'b2', '3']).str.extract(
       ....:         '(?P<letter>[ab])?(?P<digit>\d)')
       ....: 
    
      letter digit
    0      a     1
    1      b     2
    2    NaN     3
    
  • read_stata now accepts Stata 13 format (GH4291)

  • read_fwf now infers the column specifications from the first 100 rows of the file if the data has correctly separated and properly aligned columns using the delimiter provided to the function (GH4488).

  • support for nanosecond times as an offset

    Warning

    These operations require numpy >= 1.7

    Period conversions in the range of seconds and below were reworked and extended up to nanoseconds. Periods in the nanosecond range are now available.

    In [85]: date_range('2013-01-01', periods=5, freq='5N')
    
    <class 'pandas.tseries.index.DatetimeIndex'>
    [2013-01-01 00:00:00, ..., 2013-01-01 00:00:00.000000020]
    Length: 5, Freq: 5N, Timezone: None
    

    or with frequency as offset

    In [86]: date_range('2013-01-01', periods=5, freq=pd.offsets.Nano(5))
    
    <class 'pandas.tseries.index.DatetimeIndex'>
    [2013-01-01 00:00:00, ..., 2013-01-01 00:00:00.000000020]
    Length: 5, Freq: 5N, Timezone: None
    

    Timestamps can be modified in the nanosecond range

    In [87]: t = Timestamp('20130101 09:01:02')
    
    In [88]: t + pd.datetools.Nano(123)
    Timestamp('2013-01-01 09:01:02.000000123', tz=None)
    
  • A new method, isin for DataFrames, which plays nicely with boolean indexing. The argument to isin, what we’re comparing the DataFrame to, can be a DataFrame, Series, dict, or array of values. See the docs for more.

    To get the rows where any of the conditions are met:

    In [89]: dfi = DataFrame({'A': [1, 2, 3, 4], 'B': ['a', 'b', 'f', 'n']})
    
    In [90]: dfi
    
       A  B
    0  1  a
    1  2  b
    2  3  f
    3  4  n
    
    In [91]: other = DataFrame({'A': [1, 3, 3, 7], 'B': ['e', 'f', 'f', 'e']})
    
    In [92]: mask = dfi.isin(other)
    
    In [93]: mask
    
           A      B
    0   True  False
    1  False  False
    2   True   True
    3  False  False
    
    In [94]: dfi[mask.any(1)]
    
       A  B
    0  1  a
    2  3  f
    
  • Series now supports a to_frame method to convert it to a single-column DataFrame (GH5164)

  • All R datasets listed here http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html can now be loaded into Pandas objects

    import pandas.rpy.common as com
    com.load_data('Titanic')
    
  • tz_localize can infer a fall daylight savings transition based on the structure of the unlocalized data (GH4230), see the docs

  • DatetimeIndex is now in the API documentation, see the docs

  • json_normalize() is a new method to allow you to create a flat table from semi-structured JSON data. See the docs (GH1067)

  • Added PySide support for the qtpandas DataFrameModel and DataFrameWidget.

  • Python csv parser now supports usecols (GH4335)

  • DataFrame has a new interpolate method, similar to Series (GH4434, GH1892)

  • Added LastWeekOfMonth DateOffset (GH4637)

  • Added FY5253, and FY5253Quarter DateOffsets (GH4511)

    In [95]: df = DataFrame({'A': [1, 2.1, np.nan, 4.7, 5.6, 6.8],
       ....:                 'B': [.25, np.nan, np.nan, 4, 12.2, 14.4]})
       ....: 
    
    In [96]: df.interpolate()
    
         A      B
    0  1.0   0.25
    1  2.1   1.50
    2  3.4   2.75
    3  4.7   4.00
    4  5.6  12.20
    5  6.8  14.40
    

    Additionally, the method argument to interpolate has been expanded to include 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric', 'krogh', 'piecewise_polynomial', 'pchip', `polynomial`, 'spline' The new methods require scipy. Consult the Scipy reference guide and documentation for more information about when the various methods are appropriate. See the docs.

    Interpolate now also accepts a limit keyword argument. This works similar to fillna‘s limit:

    In [97]: ser = Series([1, 3, np.nan, np.nan, np.nan, 11])
    
    In [98]: ser.interpolate(limit=2)
    
    0     1
    1     3
    2     5
    3     7
    4   NaN
    5    11
    dtype: float64
    
  • to_csv now takes a date_format keyword argument that specifies how output datetime objects should be formatted. Datetimes encountered in the index, columns, and values will all have this formatting applied. (GH4313)
  • DataFrame.plot will scatter plot x versus y by passing kind='scatter' (GH2215)

Experimental

  • The new eval() function implements expression evaluation using numexpr behind the scenes. This results in large speedups for complicated expressions involving large DataFrames/Series. For example,

    In [99]: nrows, ncols = 20000, 100
    
    In [100]: df1, df2, df3, df4 = [DataFrame(randn(nrows, ncols))
       .....:                       for _ in xrange(4)]
       .....: 
    
    # eval with NumExpr backend
    In [101]: %timeit pd.eval('df1 + df2 + df3 + df4')
    100 loops, best of 3: 12.9 ms per loop
    
    # pure Python evaluation
    In [102]: %timeit df1 + df2 + df3 + df4
    10 loops, best of 3: 23 ms per loop
    

    For more details, see the the docs

  • Similar to pandas.eval, DataFrame has a new DataFrame.eval method that evaluates an expression in the context of the DataFrame. For example,

    In [103]: df = DataFrame(randn(10, 2), columns=['a', 'b'])
    
    In [104]: df.eval('a + b')
    
    0   -0.502663
    1    0.482432
    2   -0.687797
    3    1.196769
    4   -1.401357
    5    0.344361
    6   -0.121976
    7    0.651945
    8   -0.012142
    9   -2.199433
    dtype: float64
    
  • query() method has been added that allows you to select elements of a DataFrame using a natural query syntax nearly identical to Python syntax. For example,

    In [105]: n = 20
    
    In [106]: df = DataFrame(np.random.randint(n, size=(n, 3)), columns=['a', 'b', 'c'])
    
    In [107]: df.query('a < b < c')
    
        a   b   c
    1   1   7  13
    11  0   6  16
    16  5  12  18
    

    selects all the rows of df where a < b < c evaluates to True. For more details see the the docs.

  • pd.read_msgpack() and pd.to_msgpack() are now a supported method of serialization of arbitrary pandas (and python objects) in a lightweight portable binary format. See the docs

    Warning

    Since this is an EXPERIMENTAL LIBRARY, the storage format may not be stable until a future release.

    In [108]: df = DataFrame(np.random.rand(5,2),columns=list('AB'))
    
    In [109]: df.to_msgpack('foo.msg')
    
    In [110]: pd.read_msgpack('foo.msg')
    
              A         B
    0  0.111083  0.578128
    1  0.448312  0.403287
    2  0.569814  0.805589
    3  0.452454  0.660426
    4  0.693264  0.287078
    
    In [111]: s = Series(np.random.rand(5),index=date_range('20130101',periods=5))
    
    In [112]: pd.to_msgpack('foo.msg', df, s)
    
    In [113]: pd.read_msgpack('foo.msg')
    
    [          A         B
    0  0.111083  0.578128
    1  0.448312  0.403287
    2  0.569814  0.805589
    3  0.452454  0.660426
    4  0.693264  0.287078,
     2013-01-01    0.672181
    2013-01-02    0.190140
    2013-01-03    0.671657
    2013-01-04    0.101191
    2013-01-05    0.723931
    Freq: D, dtype: float64]
    

    You can pass iterator=True to iterator over the unpacked results

    In [114]: for o in pd.read_msgpack('foo.msg',iterator=True):
       .....:    print o
       .....: 
              A         B
    0  0.111083  0.578128
    1  0.448312  0.403287
    2  0.569814  0.805589
    3  0.452454  0.660426
    4  0.693264  0.287078
    2013-01-01    0.672181
    2013-01-02    0.190140
    2013-01-03    0.671657
    2013-01-04    0.101191
    2013-01-05    0.723931
    Freq: D, dtype: float64
    
  • pandas.io.gbq provides a simple way to extract from, and load data into, Google’s BigQuery Data Sets by way of pandas DataFrames. BigQuery is a high performance SQL-like database service, useful for performing ad-hoc queries against extremely large datasets. See the docs

    from pandas.io import gbq
    
    # A query to select the average monthly temperatures in the
    # in the year 2000 across the USA. The dataset,
    # publicata:samples.gsod, is available on all BigQuery accounts,
    # and is based on NOAA gsod data.
    
    query = """SELECT station_number as STATION,
    month as MONTH, AVG(mean_temp) as MEAN_TEMP
    FROM publicdata:samples.gsod
    WHERE YEAR = 2000
    GROUP BY STATION, MONTH
    ORDER BY STATION, MONTH ASC"""
    
    # Fetch the result set for this query
    
    # Your Google BigQuery Project ID
    # To find this, see your dashboard:
    # https://code.google.com/apis/console/b/0/?noredirect
    projectid = xxxxxxxxx;
    
    df = gbq.read_gbq(query, project_id = projectid)
    
    # Use pandas to process and reshape the dataset
    
    df2 = df.pivot(index='STATION', columns='MONTH', values='MEAN_TEMP')
    df3 = pandas.concat([df2.min(), df2.mean(), df2.max()],
                        axis=1,keys=["Min Tem", "Mean Temp", "Max Temp"])
    

    The resulting dataframe is:

    > df3
                Min Tem  Mean Temp    Max Temp
     MONTH
     1     -53.336667  39.827892   89.770968
     2     -49.837500  43.685219   93.437932
     3     -77.926087  48.708355   96.099998
     4     -82.892858  55.070087   97.317240
     5     -92.378261  61.428117  102.042856
     6     -77.703334  65.858888  102.900000
     7     -87.821428  68.169663  106.510714
     8     -89.431999  68.614215  105.500000
     9     -86.611112  63.436935  107.142856
     10    -78.209677  56.880838   92.103333
     11    -50.125000  48.861228   94.996428
     12    -50.332258  42.286879   94.396774

    Warning

    To use this module, you will need a BigQuery account. See <https://cloud.google.com/products/big-query> for details.

    As of 10/10/13, there is a bug in Google’s API preventing result sets from being larger than 100,000 rows. A patch is scheduled for the week of 10/14/13.

Internal Refactoring

In 0.13.0 there is a major refactor primarily to subclass Series from NDFrame, which is the base class currently for DataFrame and Panel, to unify methods and behaviors. Series formerly subclassed directly from ndarray. (GH4080, GH3862, GH816)

Warning

There are two potential incompatibilities from < 0.13.0

  • Using certain numpy functions would previously return a Series if passed a Series as an argument. This seems only to affect np.ones_like, np.empty_like, np.diff and np.where. These now return ndarrays.

    In [115]: s = Series([1,2,3,4])
    

    Numpy Usage

    In [116]: np.ones_like(s)
    array([1, 1, 1, 1])
    
    In [117]: np.diff(s)
    array([1, 1, 1])
    
    In [118]: np.where(s>1,s,np.nan)
    array([ nan,   2.,   3.,   4.])
    

    Pandonic Usage

    In [119]: Series(1,index=s.index)
    
    0    1
    1    1
    2    1
    3    1
    dtype: int64
    
    In [120]: s.diff()
    
    0   NaN
    1     1
    2     1
    3     1
    dtype: float64
    
    In [121]: s.where(s>1)
    
    0   NaN
    1     2
    2     3
    3     4
    dtype: float64
    
  • Passing a Series directly to a cython function expecting an ndarray type will no long work directly, you must pass Series.values, See Enhancing Performance

  • Series(0.5) would previously return the scalar 0.5, instead this will return a 1-element Series

  • Refactor of series.py/frame.py/panel.py to move common code to generic.py

    • added _setup_axes to created generic NDFrame structures
    • moved methods
      • from_axes,_wrap_array,axes,ix,loc,iloc,shape,empty,swapaxes,transpose,pop
      • __iter__,keys,__contains__,__len__,__neg__,__invert__
      • convert_objects,as_blocks,as_matrix,values
      • __getstate__,__setstate__ (compat remains in frame/panel)
      • __getattr__,__setattr__
      • _indexed_same,reindex_like,align,where,mask
      • fillna,replace (Series replace is now consistent with DataFrame)
      • filter (also added axis argument to selectively filter on a different axis)
      • reindex,reindex_axis,take
      • truncate (moved to become part of NDFrame)
  • These are API changes which make Panel more consistent with DataFrame

    • swapaxes on a Panel with the same axes specified now return a copy
    • support attribute access for setting
    • filter supports same api as original DataFrame filter
  • Reindex called with no arguments will now return a copy of the input object

  • Series now inherits from NDFrame rather than directly from ndarray. There are several minor changes that affect the API.

    • numpy functions that do not support the array interface will now return ndarrays rather than series, e.g. np.diff and np.ones_like
    • Series(0.5) would previously return the scalar 0.5, this is no longer supported
    • TimeSeries is now an alias for Series. the property is_time_series can be used to distinguish (if desired)
  • Refactor of Sparse objects to use BlockManager

    • Created a new block type in internals, SparseBlock, which can hold multi-dtypes and is non-consolidatable. SparseSeries and SparseDataFrame now inherit more methods from there hierarchy (Series/DataFrame), and no longer inherit from SparseArray (which instead is the object of the SparseBlock)
    • Sparse suite now supports integration with non-sparse data. Non-float sparse data is supportable (partially implemented)
    • Operations on sparse structures within DataFrames should preserve sparseness, merging type operations will convert to dense (and back to sparse), so might be somewhat inefficient
    • enable setitem on SparseSeries for boolean/integer/slices
    • SparsePanels implementation is unchanged (e.g. not using BlockManager, needs work)
  • added ftypes method to Series/DataFame, similar to dtypes, but indicates if the underlying is sparse/dense (as well as the dtype)

  • All NDFrame objects now have a _prop_attributes, which can be used to indcated various values to propogate to a new object from an existing (e.g. name in Series will follow more automatically now)

  • Internal type checking is now done via a suite of generated classes, allowing isinstance(value, klass) without having to directly import the klass, courtesy of @jtratner

  • Bug in Series update where the parent frame is not updating its cache based on changes (GH4080) or types (GH3217), fillna (GH3386)

  • Indexing with dtype conversions fixed (GH4463, GH4204)

  • Refactor Series.reindex to core/generic.py (GH4604, GH4618), allow method= in reindexing on a Series to work

  • Series.copy no longer accepts the order parameter and is now consistent with NDFrame copy

  • Refactor rename methods to core/generic.py; fixes Series.rename for (GH4605), and adds rename with the same signature for Panel

  • Refactor clip methods to core/generic.py (GH4798)

  • Refactor of _get_numeric_data/_get_bool_data to core/generic.py, allowing Series/Panel functionaility

  • Series (for index) / Panel (for items) now allow attribute access to its elements (GH1903)

    In [122]: s = Series([1,2,3],index=list('abc'))
    
    In [123]: s.b
    2
    
    In [124]: s.a = 5
    
    In [125]: s
    
    a    5
    b    2
    c    3
    dtype: int64
    

Bug Fixes

See V0.13.0 Bug Fixes for an extensive list of bugs that have been fixed in 0.13.0.

See the full release notes or issue tracker on GitHub for a complete list of all API changes, Enhancements and Bug Fixes.

v0.12.0 (July 24, 2013)

This is a major release from 0.11.0 and includes several new features and enhancements along with a large number of bug fixes.

Highlights include a consistent I/O API naming scheme, routines to read html, write multi-indexes to csv files, read & write STATA data files, read & write JSON format files, Python 3 support for HDFStore, filtering of groupby expressions via filter, and a revamped replace routine that accepts regular expressions.

API changes

  • The I/O API is now much more consistent with a set of top level reader functions accessed like pd.read_csv() that generally return a pandas object.

    • read_csv
    • read_excel
    • read_hdf
    • read_sql
    • read_json
    • read_html
    • read_stata
    • read_clipboard

    The corresponding writer functions are object methods that are accessed like df.to_csv()

    • to_csv
    • to_excel
    • to_hdf
    • to_sql
    • to_json
    • to_html
    • to_stata
    • to_clipboard
  • Fix modulo and integer division on Series,DataFrames to act similary to float dtypes to return np.nan or np.inf as appropriate (GH3590). This correct a numpy bug that treats integer and float dtypes differently.

    In [1]: p = DataFrame({ 'first' : [4,5,8], 'second' : [0,0,3] })
    
    In [2]: p % 0
    
       first  second
    0    NaN     NaN
    1    NaN     NaN
    2    NaN     NaN
    
    In [3]: p % p
    
       first  second
    0      0     NaN
    1      0     NaN
    2      0       0
    
    In [4]: p / p
    
       first    second
    0      1       inf
    1      1       inf
    2      1  1.000000
    
    In [5]: p / 0
    
       first  second
    0    inf     inf
    1    inf     inf
    2    inf     inf
    
  • Add squeeze keyword to groupby to allow reduction from DataFrame -> Series if groups are unique. This is a Regression from 0.10.1. We are reverting back to the prior behavior. This means groupby will return the same shaped objects whether the groups are unique or not. Revert this issue (GH2893) with (GH3596).

    In [6]: df2 = DataFrame([{"val1": 1, "val2" : 20}, {"val1":1, "val2": 19},
       ...:                  {"val1":1, "val2": 27}, {"val1":1, "val2": 12}])
       ...: 
    
    In [7]: def func(dataf):
       ...:     return dataf["val2"]  - dataf["val2"].mean()
       ...: 
    
    # squeezing the result frame to a series (because we have unique groups)
    In [8]: df2.groupby("val1", squeeze=True).apply(func)
    
    0    0.5
    1   -0.5
    2    7.5
    3   -7.5
    Name: 1, dtype: float64
    
    # no squeezing (the default, and behavior in 0.10.1)
    In [9]: df2.groupby("val1").apply(func)
    
            0    1    2    3
    val1                    
    1     0.5 -0.5  7.5 -7.5
    
  • Raise on iloc when boolean indexing with a label based indexer mask e.g. a boolean Series, even with integer labels, will raise. Since iloc is purely positional based, the labels on the Series are not alignable (GH3631)

    This case is rarely used, and there are plently of alternatives. This preserves the iloc API to be purely positional based.

    In [10]: df = DataFrame(lrange(5), list('ABCDE'), columns=['a'])
    
    In [11]: mask = (df.a%2 == 0)
    
    In [12]: mask
    
    A     True
    B    False
    C     True
    D    False
    E     True
    Name: a, dtype: bool
    
    # this is what you should use
    In [13]: df.loc[mask]
    
       a
    A  0
    C  2
    E  4
    
    # this will work as well
    In [14]: df.iloc[mask.values]
    
       a
    A  0
    C  2
    E  4
    

    df.iloc[mask] will raise a ValueError

  • The raise_on_error argument to plotting functions is removed. Instead, plotting functions raise a TypeError when the dtype of the object is object to remind you to avoid object arrays whenever possible and thus you should cast to an appropriate numeric dtype if you need to plot something.

  • Add colormap keyword to DataFrame plotting methods. Accepts either a matplotlib colormap object (ie, matplotlib.cm.jet) or a string name of such an object (ie, ‘jet’). The colormap is sampled to select the color for each column. Please see Colormaps for more information. (GH3860)

  • DataFrame.interpolate() is now deprecated. Please use DataFrame.fillna() and DataFrame.replace() instead. (GH3582, GH3675, GH3676)

  • the method and axis arguments of DataFrame.replace() are deprecated

  • DataFrame.replace ‘s infer_types parameter is removed and now performs conversion by default. (GH3907)

  • Add the keyword allow_duplicates to DataFrame.insert to allow a duplicate column to be inserted if True, default is False (same as prior to 0.12) (GH3679)

  • Implement __nonzero__ for NDFrame objects (GH3691, GH3696)

  • IO api

    • added top-level function read_excel to replace the following, The original API is deprecated and will be removed in a future version

      from pandas.io.parsers import ExcelFile
      xls = ExcelFile('path_to_file.xls')
      xls.parse('Sheet1', index_col=None, na_values=['NA'])
      

      With

      import pandas as pd
      pd.read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
      
    • added top-level function read_sql that is equivalent to the following

      from pandas.io.sql import read_frame
      read_frame(....)
      
  • DataFrame.to_html and DataFrame.to_latex now accept a path for their first argument (GH3702)

  • Do not allow astypes on datetime64[ns] except to object, and timedelta64[ns] to object/int (GH3425)

  • The behavior of datetime64 dtypes has changed with respect to certain so-called reduction operations (GH3726). The following operations now raise a TypeError when perfomed on a Series and return an empty Series when performed on a DataFrame similar to performing these operations on, for example, a DataFrame of slice objects:

    • sum, prod, mean, std, var, skew, kurt, corr, and cov
  • read_html now defaults to None when reading, and falls back on bs4 + html5lib when lxml fails to parse. a list of parsers to try until success is also valid

  • The internal pandas class hierarchy has changed (slightly). The previous PandasObject now is called PandasContainer and a new PandasObject has become the baseclass for PandasContainer as well as Index, Categorical, GroupBy, SparseList, and SparseArray (+ their base classes). Currently, PandasObject provides string methods (from StringMixin). (GH4090, GH4092)

  • New StringMixin that, given a __unicode__ method, gets python 2 and python 3 compatible string methods (__str__, __bytes__, and __repr__). Plus string safety throughout. Now employed in many places throughout the pandas library. (GH4090, GH4092)

I/O Enhancements

  • pd.read_html() can now parse HTML strings, files or urls and return DataFrames, courtesy of @cpcloud. (GH3477, GH3605, GH3606, GH3616). It works with a single parser backend: BeautifulSoup4 + html5lib See the docs

    You can use pd.read_html() to read the output from DataFrame.to_html() like so

    In [15]: df = DataFrame({'a': range(3), 'b': list('abc')})
    
    In [16]: print(df)
       a  b
    0  0  a
    1  1  b
    2  2  c
    
    In [17]: html = df.to_html()
    
    In [18]: alist = pd.read_html(html, infer_types=True, index_col=0)
    
    In [19]: print(df == alist[0])
          a     b
    0  True  True
    1  True  True
    2  True  True
    

    Note that alist here is a Python list so pd.read_html() and DataFrame.to_html() are not inverses.

    • pd.read_html() no longer performs hard conversion of date strings (GH3656).

    Warning

    You may have to install an older version of BeautifulSoup4, See the installation docs

  • Added module for reading and writing Stata files: pandas.io.stata (GH1512) accessable via read_stata top-level function for reading, and to_stata DataFrame method for writing, See the docs

  • Added module for reading and writing json format files: pandas.io.json accessable via read_json top-level function for reading, and to_json DataFrame method for writing, See the docs various issues (GH1226, GH3804, GH3876, GH3867, GH1305)

  • MultiIndex column support for reading and writing csv format files

    • The header option in read_csv now accepts a list of the rows from which to read the index.

    • The option, tupleize_cols can now be specified in both to_csv and read_csv, to provide compatiblity for the pre 0.12 behavior of writing and reading MultIndex columns via a list of tuples. The default in 0.12 is to write lists of tuples and not interpret list of tuples as a MultiIndex column.

      Note: The default behavior in 0.12 remains unchanged from prior versions, but starting with 0.13, the default to write and read MultiIndex columns will be in the new format. (GH3571, GH1651, GH3141)

    • If an index_col is not specified (e.g. you don’t have an index, or wrote it with df.to_csv(..., index=False), then any names on the columns index will be lost.

      In [20]: from pandas.util.testing import makeCustomDataframe as mkdf
      
      In [21]: df = mkdf(5,3,r_idx_nlevels=2,c_idx_nlevels=4)
      
      In [22]: df.to_csv('mi.csv',tupleize_cols=False)
      
      In [23]: print(open('mi.csv').read())
      C0,,C_l0_g0,C_l0_g1,C_l0_g2
      C1,,C_l1_g0,C_l1_g1,C_l1_g2
      C2,,C_l2_g0,C_l2_g1,C_l2_g2
      C3,,C_l3_g0,C_l3_g1,C_l3_g2
      R0,R1,,,
      R_l0_g0,R_l1_g0,R0C0,R0C1,R0C2
      R_l0_g1,R_l1_g1,R1C0,R1C1,R1C2
      R_l0_g2,R_l1_g2,R2C0,R2C1,R2C2
      R_l0_g3,R_l1_g3,R3C0,R3C1,R3C2
      R_l0_g4,R_l1_g4,R4C0,R4C1,R4C2
      
      In [24]: pd.read_csv('mi.csv',header=[0,1,2,3],index_col=[0,1],tupleize_cols=False)
      
      C0              C_l0_g0 C_l0_g1 C_l0_g2
      C1              C_l1_g0 C_l1_g1 C_l1_g2
      C2              C_l2_g0 C_l2_g1 C_l2_g2
      C3              C_l3_g0 C_l3_g1 C_l3_g2
      R0      R1                             
      R_l0_g0 R_l1_g0    R0C0    R0C1    R0C2
      R_l0_g1 R_l1_g1    R1C0    R1C1    R1C2
      R_l0_g2 R_l1_g2    R2C0    R2C1    R2C2
      R_l0_g3 R_l1_g3    R3C0    R3C1    R3C2
      R_l0_g4 R_l1_g4    R4C0    R4C1    R4C2
      
  • Support for HDFStore (via PyTables 3.0.0) on Python3

  • Iterator support via read_hdf that automatically opens and closes the store when iteration is finished. This is only for tables

    In [25]: path = 'store_iterator.h5'
    
    In [26]: DataFrame(randn(10,2)).to_hdf(path,'df',table=True)
    
    In [27]: for df in read_hdf(path,'df', chunksize=3):
       ....:    print(df)
       ....: 
              0         1
    0  0.810519 -1.209356
    1  0.522865  0.362902
    2 -1.050760  0.823328
              0         1
    3 -1.819253  0.473515
    4  0.215620 -1.135472
    5  0.599257 -1.636944
              0         1
    6 -0.097836  0.708607
    7 -2.129703  0.066731
    8  0.343398  1.159945
             0         1
    9 -0.87776 -0.942031
    
  • read_csv will now throw a more informative error message when a file contains no columns, e.g., all newline characters

Other Enhancements

  • DataFrame.replace() now allows regular expressions on contained Series with object dtype. See the examples section in the regular docs Replacing via String Expression

    For example you can do

    In [28]: df = DataFrame({'a': list('ab..'), 'b': [1, 2, 3, 4]})
    
    In [29]: df.replace(regex=r'\s*\.\s*', value=np.nan)
    
         a  b
    0    a  1
    1    b  2
    2  NaN  3
    3  NaN  4
    

    to replace all occurrences of the string '.' with zero or more instances of surrounding whitespace with NaN.

    Regular string replacement still works as expected. For example, you can do

    In [30]: df.replace('.', np.nan)
    
         a  b
    0    a  1
    1    b  2
    2  NaN  3
    3  NaN  4
    

    to replace all occurrences of the string '.' with NaN.

  • pd.melt() now accepts the optional parameters var_name and value_name to specify custom column names of the returned DataFrame.

  • pd.set_option() now allows N option, value pairs (GH3667).

    Let’s say that we had an option 'a.b' and another option 'b.c'. We can set them at the same time:

    In [31]: pd.get_option('a.b')
    2
    
    In [32]: pd.get_option('b.c')
    3
    
    In [33]: pd.set_option('a.b', 1, 'b.c', 4)
    
    In [34]: pd.get_option('a.b')
    1
    
    In [35]: pd.get_option('b.c')
    4
    
  • The filter method for group objects returns a subset of the original object. Suppose we want to take only elements that belong to groups with a group sum greater than 2.

    In [36]: sf = Series([1, 1, 2, 3, 3, 3])
    
    In [37]: sf.groupby(sf).filter(lambda x: x.sum() > 2)
    
    3    3
    4    3
    5    3
    dtype: int64
    

    The argument of filter must a function that, applied to the group as a whole, returns True or False.

    Another useful operation is filtering out elements that belong to groups with only a couple members.

    In [38]: dff = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc')})
    
    In [39]: dff.groupby('B').filter(lambda x: len(x) > 2)
    
       A  B
    2  2  b
    3  3  b
    4  4  b
    5  5  b
    

    Alternatively, instead of dropping the offending groups, we can return a like-indexed objects where the groups that do not pass the filter are filled with NaNs.

    In [40]: dff.groupby('B').filter(lambda x: len(x) > 2, dropna=False)
    
        A    B
    0 NaN  NaN
    1 NaN  NaN
    2   2    b
    3   3    b
    4   4    b
    5   5    b
    6 NaN  NaN
    7 NaN  NaN
    
  • Series and DataFrame hist methods now take a figsize argument (GH3834)

  • DatetimeIndexes no longer try to convert mixed-integer indexes during join operations (GH3877)

  • Timestamp.min and Timestamp.max now represent valid Timestamp instances instead of the default datetime.min and datetime.max (respectively), thanks @SleepingPills

  • read_html now raises when no tables are found and BeautifulSoup==4.2.0 is detected (GH4214)

Experimental Features

  • Added experimental CustomBusinessDay class to support DateOffsets with custom holiday calendars and custom weekmasks. (GH2301)

    Note

    This uses the numpy.busdaycalendar API introduced in Numpy 1.7 and therefore requires Numpy 1.7.0 or newer.

    In [41]: from pandas.tseries.offsets import CustomBusinessDay
    
    # As an interesting example, let's look at Egypt where
    # a Friday-Saturday weekend is observed.
    In [42]: weekmask_egypt = 'Sun Mon Tue Wed Thu'
    
    # They also observe International Workers' Day so let's
    # add that for a couple of years
    In [43]: holidays = ['2012-05-01', datetime(2013, 5, 1), np.datetime64('2014-05-01')]
    
    In [44]: bday_egypt = CustomBusinessDay(holidays=holidays, weekmask=weekmask_egypt)
    
    In [45]: dt = datetime(2013, 4, 30)
    
    In [46]: print(dt + 2 * bday_egypt)
    2013-05-05 00:00:00
    
    In [47]: dts = date_range(dt, periods=5, freq=bday_egypt).to_series()
    
    In [48]: print(Series(dts.weekday, dts).map(Series('Mon Tue Wed Thu Fri Sat Sun'.split())))
    2013-04-30    Tue
    2013-05-02    Thu
    2013-05-05    Sun
    2013-05-06    Mon
    2013-05-07    Tue
    dtype: object
    

Bug Fixes

  • Plotting functions now raise a TypeError before trying to plot anything if the associated objects have have a dtype of object (GH1818, GH3572, GH3911, GH3912), but they will try to convert object arrays to numeric arrays if possible so that you can still plot, for example, an object array with floats. This happens before any drawing takes place which elimnates any spurious plots from showing up.

  • fillna methods now raise a TypeError if the value parameter is a list or tuple.

  • Series.str now supports iteration (GH3638). You can iterate over the individual elements of each string in the Series. Each iteration yields yields a Series with either a single character at each index of the original Series or NaN. For example,

    In [49]: strs = 'go', 'bow', 'joe', 'slow'
    
    In [50]: ds = Series(strs)
    
    In [51]: for s in ds.str:
       ....:     print(s)
       ....: 
    0    g
    1    b
    2    j
    3    s
    dtype: object
    0    o
    1    o
    2    o
    3    l
    dtype: object
    0    NaN
    1      w
    2      e
    3      o
    dtype: object
    0    NaN
    1    NaN
    2    NaN
    3      w
    dtype: object
    
    In [52]: s
    
    0    NaN
    1    NaN
    2    NaN
    3      w
    dtype: object
    
    In [53]: s.dropna().values.item() == 'w'
    True
    

    The last element yielded by the iterator will be a Series containing the last element of the longest string in the Series with all other elements being NaN. Here since 'slow' is the longest string and there are no other strings with the same length 'w' is the only non-null string in the yielded Series.

  • HDFStore

    • will retain index attributes (freq,tz,name) on recreation (GH3499)
    • will warn with a AttributeConflictWarning if you are attempting to append an index with a different frequency than the existing, or attempting to append an index with a different name than the existing
    • support datelike columns with a timezone as data_columns (GH2852)
  • Non-unique index support clarified (GH3468).

    • Fix assigning a new index to a duplicate index in a DataFrame would fail (GH3468)
    • Fix construction of a DataFrame with a duplicate index
    • ref_locs support to allow duplicative indices across dtypes, allows iget support to always find the index (even across dtypes) (GH2194)
    • applymap on a DataFrame with a non-unique index now works (removed warning) (GH2786), and fix (GH3230)
    • Fix to_csv to handle non-unique columns (GH3495)
    • Duplicate indexes with getitem will return items in the correct order (GH3455, GH3457) and handle missing elements like unique indices (GH3561)
    • Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562)
    • Concat to produce a non-unique columns when duplicates are across dtypes is fixed (GH3602)
    • Allow insert/delete to non-unique columns (GH3679)
    • Non-unique indexing with a slice via loc and friends fixed (GH3659)
    • Allow insert/delete to non-unique columns (GH3679)
    • Extend reindex to correctly deal with non-unique indices (GH3679)
    • DataFrame.itertuples() now works with frames with duplicate column names (GH3873)
    • Bug in non-unique indexing via iloc (GH4017); added takeable argument to reindex for location-based taking
    • Allow non-unique indexing in series via .ix/.loc and __getitem__ (GH4246)
    • Fixed non-unique indexing memory allocation issue with .ix/.loc (GH4280)
  • DataFrame.from_records did not accept empty recarrays (GH3682)

  • read_html now correctly skips tests (GH3741)

  • Fixed a bug where DataFrame.replace with a compiled regular expression in the to_replace argument wasn’t working (GH3907)

  • Improved network test decorator to catch IOError (and therefore URLError as well). Added with_connectivity_check decorator to allow explicitly checking a website as a proxy for seeing if there is network connectivity. Plus, new optional_args decorator factory for decorators. (GH3910, GH3914)

  • Fixed testing issue where too many sockets where open thus leading to a connection reset issue (GH3982, GH3985, GH4028, GH4054)

  • Fixed failing tests in test_yahoo, test_google where symbols were not retrieved but were being accessed (GH3982, GH3985, GH4028, GH4054)

  • Series.hist will now take the figure from the current environment if one is not passed

  • Fixed bug where a 1xN DataFrame would barf on a 1xN mask (GH4071)

  • Fixed running of tox under python3 where the pickle import was getting rewritten in an incompatible way (GH4062, GH4063)

  • Fixed bug where sharex and sharey were not being passed to grouped_hist (GH4089)

  • Fixed bug in DataFrame.replace where a nested dict wasn’t being iterated over when regex=False (GH4115)

  • Fixed bug in the parsing of microseconds when using the format argument in to_datetime (GH4152)

  • Fixed bug in PandasAutoDateLocator where invert_xaxis triggered incorrectly MilliSecondLocator (GH3990)

  • Fixed bug in plotting that wasn’t raising on invalid colormap for matplotlib 1.1.1 (GH4215)

  • Fixed the legend displaying in DataFrame.plot(kind='kde') (GH4216)

  • Fixed bug where Index slices weren’t carrying the name attribute (GH4226)

  • Fixed bug in initializing DatetimeIndex with an array of strings in a certain time zone (GH4229)

  • Fixed bug where html5lib wasn’t being properly skipped (GH4265)

  • Fixed bug where get_data_famafrench wasn’t using the correct file edges (GH4281)

See the full release notes or issue tracker on GitHub for a complete list.

v0.11.0 (April 22, 2013)

This is a major release from 0.10.1 and includes many new features and enhancements along with a large number of bug fixes. The methods of Selecting Data have had quite a number of additions, and Dtype support is now full-fledged. There are also a number of important API changes that long-time pandas users should pay close attention to.

There is a new section in the documentation, 10 Minutes to Pandas, primarily geared to new users.

There is a new section in the documentation, Cookbook, a collection of useful recipes in pandas (and that we want contributions!).

There are several libraries that are now Recommended Dependencies

Selection Choices

Starting in 0.11.0, object selection has had a number of user-requested additions in order to support more explicit location based indexing. Pandas now supports three types of multi-axis indexing.

  • .loc is strictly label based, will raise KeyError when the items are not found, allowed inputs are:

    • A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index. This use is not an integer position along the index)
    • A list or array of labels ['a', 'b', 'c']
    • A slice object with labels 'a':'f', (note that contrary to usual python slices, both the start and the stop are included!)
    • A boolean array

    See more at Selection by Label

  • .iloc is strictly integer position based (from 0 to length-1 of the axis), will raise IndexError when the requested indicies are out of bounds. Allowed inputs are:

    • An integer e.g. 5
    • A list or array of integers [4, 3, 0]
    • A slice object with ints 1:7
    • A boolean array

    See more at Selection by Position

  • .ix supports mixed integer and label based access. It is primarily label based, but will fallback to integer positional access. .ix is the most general and will support any of the inputs to .loc and .iloc, as well as support for floating point label schemes. .ix is especially useful when dealing with mixed positional and label based hierarchial indexes.

    As using integer slices with .ix have different behavior depending on whether the slice is interpreted as position based or label based, it’s usually better to be explicit and use .iloc or .loc.

    See more at Advanced Indexing, Advanced Hierarchical and Fallback Indexing

Selection Deprecations

Starting in version 0.11.0, these methods may be deprecated in future versions.

  • irow
  • icol
  • iget_value

See the section Selection by Position for substitutes.

Dtypes

Numeric dtypes will propagate and can coexist in DataFrames. If a dtype is passed (either directly via the dtype keyword, a passed ndarray, or a passed Series, then it will be preserved in DataFrame operations. Furthermore, different numeric dtypes will NOT be combined. The following example will give you a taste.

In [1]: df1 = DataFrame(randn(8, 1), columns = ['A'], dtype = 'float32')

In [2]: df1

          A
0  1.308826
1  2.067029
2  0.630566
3 -0.604773
4 -0.596865
5  0.027871
6  0.804940
7 -1.312176

In [3]: df1.dtypes

A    float32
dtype: object

In [4]: df2 = DataFrame(dict( A = Series(randn(8),dtype='float16'),
   ...:                       B = Series(randn(8)),
   ...:                       C = Series(randn(8),dtype='uint8') ))
   ...: 

In [5]: df2

          A         B    C
0  0.472656 -0.578247    0
1 -0.213745  0.164998    0
2 -1.093750  0.276205    0
3 -0.649902 -0.021671    0
4 -0.484863 -2.725511    1
5 -0.455078  0.681353  255
6  0.995117 -0.507806    1
7  0.304443 -0.940780  255

In [6]: df2.dtypes

A    float16
B    float64
C      uint8
dtype: object

# here you get some upcasting
In [7]: df3 = df1.reindex_like(df2).fillna(value=0.0) + df2

In [8]: df3

          A         B    C
0  1.781482 -0.578247    0
1  1.853283  0.164998    0
2 -0.463184  0.276205    0
3 -1.254676 -0.021671    0
4 -1.081729 -2.725511    1
5 -0.427207  0.681353  255
6  1.800058 -0.507806    1
7 -1.007733 -0.940780  255

In [9]: df3.dtypes

A    float32
B    float64
C    float64
dtype: object

Dtype Conversion

This is lower-common-denomicator upcasting, meaning you get the dtype which can accomodate all of the types

In [10]: df3.values.dtype
dtype('float64')

Conversion

In [11]: df3.astype('float32').dtypes

A    float32
B    float32
C    float32
dtype: object

Mixed Conversion

In [12]: df3['D'] = '1.'

In [13]: df3['E'] = '1'

In [14]: df3.convert_objects(convert_numeric=True).dtypes

A    float32
B    float64
C    float64
D    float64
E      int64
dtype: object

# same, but specific dtype conversion
In [15]: df3['D'] = df3['D'].astype('float16')

In [16]: df3['E'] = df3['E'].astype('int32')

In [17]: df3.dtypes

A    float32
B    float64
C    float64
D    float16
E      int32
dtype: object

Forcing Date coercion (and setting NaT when not datelike)

In [18]: s = Series([datetime(2001,1,1,0,0), 'foo', 1.0, 1,
   ....:             Timestamp('20010104'), '20010105'],dtype='O')
   ....: 

In [19]: s.convert_objects(convert_dates='coerce')

0   2001-01-01 00:00:00
1                   NaT
2                   NaT
3                   NaT
4   2001-01-04 00:00:00
5   2001-01-05 00:00:00
dtype: datetime64[ns]

Dtype Gotchas

Platform Gotchas

Starting in 0.11.0, construction of DataFrame/Series will use default dtypes of int64 and float64, regardless of platform. This is not an apparent change from earlier versions of pandas. If you specify dtypes, they WILL be respected, however (GH2837)

The following will all result in int64 dtypes

In [20]: DataFrame([1,2],columns=['a']).dtypes

a    int64
dtype: object

In [21]: DataFrame({'a' : [1,2] }).dtypes

a    int64
dtype: object

In [22]: DataFrame({'a' : 1 }, index=range(2)).dtypes

a    int64
dtype: object

Keep in mind that DataFrame(np.array([1,2])) WILL result in int32 on 32-bit platforms!

Upcasting Gotchas

Performing indexing operations on integer type data can easily upcast the data. The dtype of the input data will be preserved in cases where nans are not introduced.

In [23]: dfi = df3.astype('int32')

In [24]: dfi['D'] = dfi['D'].astype('int64')

In [25]: dfi

   A  B    C  D  E
0  1  0    0  1  1
1  1  0    0  1  1
2  0  0    0  1  1
3 -1  0    0  1  1
4 -1 -2    1  1  1
5  0  0  255  1  1
6  1  0    1  1  1
7 -1  0  255  1  1

In [26]: dfi.dtypes

A    int32
B    int32
C    int32
D    int64
E    int32
dtype: object

In [27]: casted = dfi[dfi>0]

In [28]: casted

    A   B    C  D  E
0   1 NaN  NaN  1  1
1   1 NaN  NaN  1  1
2 NaN NaN  NaN  1  1
3 NaN NaN  NaN  1  1
4 NaN NaN    1  1  1
5 NaN NaN  255  1  1
6   1 NaN    1  1  1
7 NaN NaN  255  1  1

In [29]: casted.dtypes

A    float64
B    float64
C    float64
D      int64
E      int32
dtype: object

While float dtypes are unchanged.

In [30]: df4 = df3.copy()

In [31]: df4['A'] = df4['A'].astype('float32')

In [32]: df4.dtypes

A    float32
B    float64
C    float64
D    float16
E      int32
dtype: object

In [33]: casted = df4[df4>0]

In [34]: casted

          A         B    C  D  E
0  1.781482       NaN  NaN  1  1
1  1.853283  0.164998  NaN  1  1
2       NaN  0.276205  NaN  1  1
3       NaN       NaN  NaN  1  1
4       NaN       NaN    1  1  1
5       NaN  0.681353  255  1  1
6  1.800058       NaN    1  1  1
7       NaN       NaN  255  1  1

In [35]: casted.dtypes

A    float32
B    float64
C    float64
D    float16
E      int32
dtype: object

Datetimes Conversion

Datetime64[ns] columns in a DataFrame (or a Series) allow the use of np.nan to indicate a nan value, in addition to the traditional NaT, or not-a-time. This allows convenient nan setting in a generic way. Furthermore datetime64[ns] columns are created by default, when passed datetimelike objects (this change was introduced in 0.10.1) (GH2809, GH2810)

In [36]: df = DataFrame(randn(6,2),date_range('20010102',periods=6),columns=['A','B'])

In [37]: df['timestamp'] = Timestamp('20010103')

In [38]: df

                   A         B           timestamp
2001-01-02  0.160712  0.878113 2001-01-03 00:00:00
2001-01-03  0.713258 -1.101765 2001-01-03 00:00:00
2001-01-04 -0.734267 -1.294560 2001-01-03 00:00:00
2001-01-05  0.972975  1.531484 2001-01-03 00:00:00
2001-01-06  0.026736 -0.603001 2001-01-03 00:00:00
2001-01-07  0.172869 -0.889618 2001-01-03 00:00:00

# datetime64[ns] out of the box
In [39]: df.get_dtype_counts()

datetime64[ns]    1
float64           2
dtype: int64

# use the traditional nan, which is mapped to NaT internally
In [40]: df.ix[2:4,['A','timestamp']] = np.nan

In [41]: df

                   A         B           timestamp
2001-01-02  0.160712  0.878113 2001-01-03 00:00:00
2001-01-03  0.713258 -1.101765 2001-01-03 00:00:00
2001-01-04       NaN -1.294560                 NaT
2001-01-05       NaN  1.531484                 NaT
2001-01-06  0.026736 -0.603001 2001-01-03 00:00:00
2001-01-07  0.172869 -0.889618 2001-01-03 00:00:00

Astype conversion on datetime64[ns] to object, implicity converts NaT to np.nan

In [42]: import datetime

In [43]: s = Series([datetime.datetime(2001, 1, 2, 0, 0) for i in range(3)])

In [44]: s.dtype
dtype('<M8[ns]')

In [45]: s[1] = np.nan

In [46]: s

0   2001-01-02 00:00:00
1                   NaT
2   2001-01-02 00:00:00
dtype: datetime64[ns]

In [47]: s.dtype
dtype('<M8[ns]')

In [48]: s = s.astype('O')

In [49]: s

0    2001-01-02 00:00:00
1                    NaN
2    2001-01-02 00:00:00
dtype: object

In [50]: s.dtype
dtype('O')

API changes

  • Added to_series() method to indicies, to facilitate the creation of indexers (GH3275)
  • HDFStore
    • added the method select_column to select a single column from a table as a Series.
    • deprecated the unique method, can be replicated by select_column(key,column).unique()
    • min_itemsize parameter to append will now automatically create data_columns for passed keys

Enhancements

  • Improved performance of df.to_csv() by up to 10x in some cases. (GH3059)

  • Numexpr is now a Recommended Dependencies, to accelerate certain types of numerical and boolean operations

  • Bottleneck is now a Recommended Dependencies, to accelerate certain types of nan operations

  • HDFStore

    • support read_hdf/to_hdf API similar to read_csv/to_csv

      In [51]: df = DataFrame(dict(A=lrange(5), B=lrange(5)))
      
      In [52]: df.to_hdf('store.h5','table',append=True)
      
      In [53]: read_hdf('store.h5', 'table', where = ['index>2'])
      
         A  B
      3  3  3
      4  4  4
      
    • provide dotted attribute access to get from stores, e.g. store.df == store['df']

    • new keywords iterator=boolean, and chunksize=number_in_a_chunk are provided to support iteration on select and select_as_multiple (GH3076)

  • You can now select timestamps from an unordered timeseries similarly to an ordered timeseries (GH2437)

  • You can now select with a string from a DataFrame with a datelike index, in a similar way to a Series (GH3070)

    In [54]: idx = date_range("2001-10-1", periods=5, freq='M')
    
    In [55]: ts = Series(np.random.rand(len(idx)),index=idx)
    
    In [56]: ts['2001']
    
    2001-10-31    0.817081
    2001-11-30    0.304213
    2001-12-31    0.819363
    Freq: M, dtype: float64
    
    In [57]: df = DataFrame(dict(A = ts))
    
    In [58]: df['2001']
    
                       A
    2001-10-31  0.817081
    2001-11-30  0.304213
    2001-12-31  0.819363
    
  • Squeeze to possibly remove length 1 dimensions from an object.

    In [59]: p = Panel(randn(3,4,4),items=['ItemA','ItemB','ItemC'],
       ....:                    major_axis=date_range('20010102',periods=4),
       ....:                    minor_axis=['A','B','C','D'])
       ....: 
    
    In [60]: p
    
    <class 'pandas.core.panel.Panel'>
    Dimensions: 3 (items) x 4 (major_axis) x 4 (minor_axis)
    Items axis: ItemA to ItemC
    Major_axis axis: 2001-01-02 00:00:00 to 2001-01-05 00:00:00
    Minor_axis axis: A to D
    
    In [61]: p.reindex(items=['ItemA']).squeeze()
    
                       A         B         C         D
    2001-01-02  0.139801  2.272044  0.342625  1.367067
    2001-01-03  1.799305  0.590738  0.091017  0.702080
    2001-01-04  0.295119  1.646173 -0.463222 -0.562252
    2001-01-05  0.185880  0.315476  0.115977 -0.290793
    
    In [62]: p.reindex(items=['ItemA'],minor=['B']).squeeze()
    
    2001-01-02    2.272044
    2001-01-03    0.590738
    2001-01-04    1.646173
    2001-01-05    0.315476
    Freq: D, Name: B, dtype: float64
    
  • In pd.io.data.Options,

    • Fix bug when trying to fetch data for the current month when already past expiry.
    • Now using lxml to scrape html instead of BeautifulSoup (lxml was faster).
    • New instance variables for calls and puts are automatically created when a method that creates them is called. This works for current month where the instance variables are simply calls and puts. Also works for future expiry months and save the instance variable as callsMMYY or putsMMYY, where MMYY are, respectively, the month and year of the option’s expiry.
    • Options.get_near_stock_price now allows the user to specify the month for which to get relevant options data.
    • Options.get_forward_data now has optional kwargs near and above_below. This allows the user to specify if they would like to only return forward looking data for options near the current stock price. This just obtains the data from Options.get_near_stock_price instead of Options.get_xxx_data() (GH2758).
  • Cursor coordinate information is now displayed in time-series plots.

  • added option display.max_seq_items to control the number of elements printed per sequence pprinting it. (GH2979)

  • added option display.chop_threshold to control display of small numerical values. (GH2739)

  • added option display.max_info_rows to prevent verbose_info from being calculated for frames above 1M rows (configurable). (GH2807, GH2918)

  • value_counts() now accepts a “normalize” argument, for normalized histograms. (GH2710).

  • DataFrame.from_records now accepts not only dicts but any instance of the collections.Mapping ABC.

  • added option display.mpl_style providing a sleeker visual style for plots. Based on https://gist.github.com/huyng/816622 (GH3075).

  • Treat boolean values as integers (values 1 and 0) for numeric operations. (GH2641)

  • to_html() now accepts an optional “escape” argument to control reserved HTML character escaping (enabled by default) and escapes &, in addition to < and >. (GH2919)

See the full release notes or issue tracker on GitHub for a complete list.

v0.10.1 (January 22, 2013)

This is a minor release from 0.10.0 and includes new features, enhancements, and bug fixes. In particular, there is substantial new HDFStore functionality contributed by Jeff Reback.

An undesired API breakage with functions taking the inplace option has been reverted and deprecation warnings added.

API changes

  • Functions taking an inplace option return the calling object as before. A deprecation message has been added
  • Groupby aggregations Max/Min no longer exclude non-numeric data (GH2700)
  • Resampling an empty DataFrame now returns an empty DataFrame instead of raising an exception (GH2640)
  • The file reader will now raise an exception when NA values are found in an explicitly specified integer column instead of converting the column to float (GH2631)
  • DatetimeIndex.unique now returns a DatetimeIndex with the same name and
  • timezone instead of an array (GH2563)

New features

  • MySQL support for database (contribution from Dan Allan)

HDFStore

You may need to upgrade your existing data files. Please visit the compatibility section in the main docs.

You can designate (and index) certain columns that you want to be able to perform queries on a table, by passing a list to data_columns

In [1]: store = HDFStore('store.h5')

In [2]: df = DataFrame(randn(8, 3), index=date_range('1/1/2000', periods=8),
   ...:            columns=['A', 'B', 'C'])
   ...: 

In [3]: df['string'] = 'foo'

In [4]: df.ix[4:6,'string'] = np.nan

In [5]: df.ix[7:9,'string'] = 'bar'

In [6]: df['string2'] = 'cool'

In [7]: df

                   A         B         C string string2
2000-01-01  1.169914 -0.032602 -0.448002    foo    cool
2000-01-02 -0.266458 -1.046759  0.462822    foo    cool
2000-01-03 -1.550374  0.076369 -0.245549    foo    cool
2000-01-04  0.537823 -0.681876  0.816955    foo    cool
2000-01-05  2.245090  0.344342  0.391808    NaN    cool
2000-01-06  1.189318 -0.037077 -0.853874    NaN    cool
2000-01-07 -2.979144  0.981169 -0.842938    foo    cool
2000-01-08  0.880603  1.864823  0.442713    bar    cool

# on-disk operations
In [8]: store.append('df', df, data_columns = ['B','C','string','string2'])

In [9]: store.select('df',[ 'B > 0', 'string == foo' ])

                   A         B         C string string2
2000-01-03 -1.550374  0.076369 -0.245549    foo    cool
2000-01-07 -2.979144  0.981169 -0.842938    foo    cool

# this is in-memory version of this type of selection
In [10]: df[(df.B > 0) & (df.string == 'foo')]

                   A         B         C string string2
2000-01-03 -1.550374  0.076369 -0.245549    foo    cool
2000-01-07 -2.979144  0.981169 -0.842938    foo    cool

Retrieving unique values in an indexable or data column.

In [11]: import warnings

In [12]: with warnings.catch_warnings():
   ....:     warnings.simplefilter('ignore', category=UserWarning)
   ....:     store.unique('df','index')
   ....:     store.unique('df','string')
   ....: 

You can now store datetime64 in data columns

In [13]: df_mixed               = df.copy()

In [14]: df_mixed['datetime64'] = Timestamp('20010102')

In [15]: df_mixed.ix[3:4,['A','B']] = np.nan

In [16]: store.append('df_mixed', df_mixed)

In [17]: df_mixed1 = store.select('df_mixed')

In [18]: df_mixed1

                   A         B         C string string2          datetime64
2000-01-01  1.169914 -0.032602 -0.448002    foo    cool 2001-01-02 00:00:00
2000-01-02 -0.266458 -1.046759  0.462822    foo    cool 2001-01-02 00:00:00
2000-01-03 -1.550374  0.076369 -0.245549    foo    cool 2001-01-02 00:00:00
2000-01-04       NaN       NaN  0.816955    foo    cool 2001-01-02 00:00:00
2000-01-05  2.245090  0.344342  0.391808    NaN    cool 2001-01-02 00:00:00
2000-01-06  1.189318 -0.037077 -0.853874    NaN    cool 2001-01-02 00:00:00
2000-01-07 -2.979144  0.981169 -0.842938    foo    cool 2001-01-02 00:00:00
2000-01-08  0.880603  1.864823  0.442713    bar    cool 2001-01-02 00:00:00

In [19]: df_mixed1.get_dtype_counts()

datetime64[ns]    1
float64           3
object            2
dtype: int64

You can pass columns keyword to select to filter a list of the return columns, this is equivalent to passing a Term('columns',list_of_columns_to_filter)

In [20]: store.select('df',columns = ['A','B'])

                   A         B
2000-01-01  1.169914 -0.032602
2000-01-02 -0.266458 -1.046759
2000-01-03 -1.550374  0.076369
2000-01-04  0.537823 -0.681876
2000-01-05  2.245090  0.344342
2000-01-06  1.189318 -0.037077
2000-01-07 -2.979144  0.981169
2000-01-08  0.880603  1.864823

HDFStore now serializes multi-index dataframes when appending tables.

In [21]: index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
   ....:                            ['one', 'two', 'three']],
   ....:                    labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
   ....:                            [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
   ....:                    names=['foo', 'bar'])
   ....: 

In [22]: df = DataFrame(np.random.randn(10, 3), index=index,
   ....:                columns=['A', 'B', 'C'])
   ....: 

In [23]: df

                  A         B         C
foo bar                                
foo one    1.147584  0.189539  1.351470
    two   -1.616398 -0.932665  1.293128
    three  1.143863 -0.303676  0.306567
bar one   -0.737894  0.555493  0.433300
    two    0.806094 -0.029454 -0.815647
baz two   -0.967099  0.651658  0.599729
    three -0.988293  0.595844 -0.879140
qux one   -0.734143  0.608219  0.479690
    two    0.339981 -0.793694  0.624566
    three -0.275204  1.165779  1.562324

In [24]: store.append('mi',df)

In [25]: store.select('mi')

                  A         B         C
foo bar                                
foo one    1.147584  0.189539  1.351470
    two   -1.616398 -0.932665  1.293128
    three  1.143863 -0.303676  0.306567
bar one   -0.737894  0.555493  0.433300
    two    0.806094 -0.029454 -0.815647
baz two   -0.967099  0.651658  0.599729
    three -0.988293  0.595844 -0.879140
qux one   -0.734143  0.608219  0.479690
    two    0.339981 -0.793694  0.624566
    three -0.275204  1.165779  1.562324

# the levels are automatically included as data columns
In [26]: store.select('mi', Term('foo=bar'))

                A         B         C
foo bar                              
bar one -0.737894  0.555493  0.433300
    two  0.806094 -0.029454 -0.815647

Multi-table creation via append_to_multiple and selection via select_as_multiple can create/select from multiple tables and return a combined result, by using where on a selector table.

In [27]: df_mt = DataFrame(randn(8, 6), index=date_range('1/1/2000', periods=8),
   ....:                                columns=['A', 'B', 'C', 'D', 'E', 'F'])
   ....: 

In [28]: df_mt['foo'] = 'bar'

# you can also create the tables individually
In [29]: store.append_to_multiple({ 'df1_mt' : ['A','B'], 'df2_mt' : None }, df_mt, selector = 'df1_mt')

In [30]: store

<class 'pandas.io.pytables.HDFStore'>
File path: store.h5
/df                  frame_table  (typ->appendable,nrows->8,ncols->5,indexers->[index],dc->[B,C,string,string2])
/df1_mt              frame_table  (typ->appendable,nrows->8,ncols->2,indexers->[index],dc->[A,B])               
/df2_mt              frame_table  (typ->appendable,nrows->8,ncols->5,indexers->[index])                         
/df_mixed            frame_table  (typ->appendable,nrows->8,ncols->6,indexers->[index])                         
/mi                  frame_table  (typ->appendable_multi,nrows->10,ncols->5,indexers->[index],dc->[bar,foo])    

# indiviual tables were created
In [31]: store.select('df1_mt')

                   A         B
2000-01-01 -0.304535  0.915705
2000-01-02 -0.093588  0.180821
2000-01-03 -0.823892 -1.287431
2000-01-04 -0.662801  0.537935
2000-01-05 -0.142331  0.178195
2000-01-06 -0.858392 -1.247307
2000-01-07  0.041545  0.151262
2000-01-08 -0.610842  0.876753

In [32]: store.select('df2_mt')

                   C         D         E         F  foo
2000-01-01 -0.861034 -0.508141  0.997194 -0.683079  bar
2000-01-02 -1.011643 -1.987686  2.081449  0.372236  bar
2000-01-03 -1.168709  0.591769  0.062839 -1.500639  bar
2000-01-04  0.619828  1.656783 -0.019515  1.040257  bar
2000-01-05 -0.159487 -0.892376 -0.813754  0.406858  bar
2000-01-06 -0.559815  0.474386  1.001631  1.095733  bar
2000-01-07 -1.002943 -1.863962  0.896348 -0.758545  bar
2000-01-08  1.074872 -0.887162 -0.820008 -0.899952  bar

# as a multiple
In [33]: store.select_as_multiple(['df1_mt','df2_mt'], where = [ 'A>0','B>0' ], selector = 'df1_mt')

                   A         B         C         D         E         F  foo
2000-01-07  0.041545  0.151262 -1.002943 -1.863962  0.896348 -0.758545  bar

Enhancements

  • HDFStore now can read native PyTables table format tables
  • You can pass nan_rep = 'my_nan_rep' to append, to change the default nan representation on disk (which converts to/from np.nan), this defaults to nan.
  • You can pass index to append. This defaults to True. This will automagically create indicies on the indexables and data columns of the table
  • You can pass chunksize=an integer to append, to change the writing chunksize (default is 50000). This will signficantly lower your memory usage on writing.
  • You can pass expectedrows=an integer to the first append, to set the TOTAL number of expectedrows that PyTables will expected. This will optimize read/write performance.
  • Select now supports passing start and stop to provide selection space limiting in selection.
  • Greatly improved ISO8601 (e.g., yyyy-mm-dd) date parsing for file parsers (GH2698)
  • Allow DataFrame.merge to handle combinatorial sizes too large for 64-bit integer (GH2690)
  • Series now has unary negation (-series) and inversion (~series) operators (GH2686)
  • DataFrame.plot now includes a logx parameter to change the x-axis to log scale (GH2327)
  • Series arithmetic operators can now handle constant and ndarray input (GH2574)
  • ExcelFile now takes a kind argument to specify the file type (GH2613)
  • A faster implementation for Series.str methods (GH2602)

Bug Fixes

  • HDFStore tables can now store float32 types correctly (cannot be mixed with float64 however)
  • Fixed Google Analytics prefix when specifying request segment (GH2713).
  • Function to reset Google Analytics token store so users can recover from improperly setup client secrets (GH2687).
  • Fixed groupby bug resulting in segfault when passing in MultiIndex (GH2706)
  • Fixed bug where passing a Series with datetime64 values into to_datetime results in bogus output values (GH2699)
  • Fixed bug in pattern in HDFStore expressions when pattern is not a valid regex (GH2694)
  • Fixed performance issues while aggregating boolean data (GH2692)
  • When given a boolean mask key and a Series of new values, Series __setitem__ will now align the incoming values with the original Series (GH2686)
  • Fixed MemoryError caused by performing counting sort on sorting MultiIndex levels with a very large number of combinatorial values (GH2684)
  • Fixed bug that causes plotting to fail when the index is a DatetimeIndex with a fixed-offset timezone (GH2683)
  • Corrected businessday subtraction logic when the offset is more than 5 bdays and the starting date is on a weekend (GH2680)
  • Fixed C file parser behavior when the file has more columns than data (GH2668)
  • Fixed file reader bug that misaligned columns with data in the presence of an implicit column and a specified usecols value
  • DataFrames with numerical or datetime indices are now sorted prior to plotting (GH2609)
  • Fixed DataFrame.from_records error when passed columns, index, but empty records (GH2633)
  • Several bug fixed for Series operations when dtype is datetime64 (GH2689, GH2629, GH2626)

See the full release notes or issue tracker on GitHub for a complete list.

v0.10.0 (December 17, 2012)

This is a major release from 0.9.1 and includes many new features and enhancements along with a large number of bug fixes. There are also a number of important API changes that long-time pandas users should pay close attention to.

File parsing new features

The delimited file parsing engine (the guts of read_csv and read_table) has been rewritten from the ground up and now uses a fraction the amount of memory while parsing, while being 40% or more faster in most use cases (in some cases much faster).

There are also many new features:

  • Much-improved Unicode handling via the encoding option.
  • Column filtering (usecols)
  • Dtype specification (dtype argument)
  • Ability to specify strings to be recognized as True/False
  • Ability to yield NumPy record arrays (as_recarray)
  • High performance delim_whitespace option
  • Decimal format (e.g. European format) specification
  • Easier CSV dialect options: escapechar, lineterminator, quotechar, etc.
  • More robust handling of many exceptional kinds of files observed in the wild

API changes

Deprecated DataFrame BINOP TimeSeries special case behavior

The default behavior of binary operations between a DataFrame and a Series has always been to align on the DataFrame’s columns and broadcast down the rows, except in the special case that the DataFrame contains time series. Since there are now method for each binary operator enabling you to specify how you want to broadcast, we are phasing out this special case (Zen of Python: Special cases aren’t special enough to break the rules). Here’s what I’m talking about:

In [1]: import pandas as pd

In [2]: df = pd.DataFrame(np.random.randn(6, 4),
   ...:                   index=pd.date_range('1/1/2000', periods=6))
   ...: 

In [3]: df

                   0         1         2         3
2000-01-01 -0.437156  0.810439  0.557595  0.326366
2000-01-02  1.017915  0.589005 -1.001091 -0.651397
2000-01-03  0.729653  0.601779  0.164518 -1.328376
2000-01-04 -0.525913  0.924822  1.249718  2.449376
2000-01-05  0.434927 -2.018356  0.986722 -0.958101
2000-01-06  0.871229  0.764551 -0.330008  2.672247

# deprecated now
In [4]: df - df[0]

            0         1         2         3
2000-01-01  0  1.247594  0.994751  0.763521
2000-01-02  0 -0.428910 -2.019006 -1.669312
2000-01-03  0 -0.127874 -0.565135 -2.058029
2000-01-04  0  1.450735  1.775631  2.975288
2000-01-05  0 -2.453283  0.551794 -1.393028
2000-01-06  0 -0.106678 -1.201236  1.801019

# Change your code to
In [5]: df.sub(df[0], axis=0) # align on axis 0 (rows)

            0         1         2         3
2000-01-01  0  1.247594  0.994751  0.763521
2000-01-02  0 -0.428910 -2.019006 -1.669312
2000-01-03  0 -0.127874 -0.565135 -2.058029
2000-01-04  0  1.450735  1.775631  2.975288
2000-01-05  0 -2.453283  0.551794 -1.393028
2000-01-06  0 -0.106678 -1.201236  1.801019

You will get a deprecation warning in the 0.10.x series, and the deprecated functionality will be removed in 0.11 or later.

Altered resample default behavior

The default time series resample binning behavior of daily D and higher frequencies has been changed to closed='left', label='left'. Lower nfrequencies are unaffected. The prior defaults were causing a great deal of confusion for users, especially resampling data to daily frequency (which labeled the aggregated group with the end of the interval: the next day).

Note:

In [6]: dates = pd.date_range('1/1/2000', '1/5/2000', freq='4h')

In [7]: series = Series(np.arange(len(dates)), index=dates)

In [8]: series

2000-01-01 00:00:00     0
2000-01-01 04:00:00     1
2000-01-01 08:00:00     2
2000-01-01 12:00:00     3
2000-01-01 16:00:00     4
2000-01-01 20:00:00     5
2000-01-02 00:00:00     6
2000-01-02 04:00:00     7
2000-01-02 08:00:00     8
2000-01-02 12:00:00     9
2000-01-02 16:00:00    10
2000-01-02 20:00:00    11
2000-01-03 00:00:00    12
2000-01-03 04:00:00    13
2000-01-03 08:00:00    14
2000-01-03 12:00:00    15
2000-01-03 16:00:00    16
2000-01-03 20:00:00    17
2000-01-04 00:00:00    18
2000-01-04 04:00:00    19
2000-01-04 08:00:00    20
2000-01-04 12:00:00    21
2000-01-04 16:00:00    22
2000-01-04 20:00:00    23
2000-01-05 00:00:00    24
Freq: 4H, dtype: int64

In [9]: series.resample('D', how='sum')

2000-01-01     15
2000-01-02     51
2000-01-03     87
2000-01-04    123
2000-01-05     24
Freq: D, dtype: int64

# old behavior
In [10]: series.resample('D', how='sum', closed='right', label='right')

2000-01-01      0
2000-01-02     21
2000-01-03     57
2000-01-04     93
2000-01-05    129
Freq: D, dtype: int64
  • Infinity and negative infinity are no longer treated as NA by isnull and notnull. That they every were was a relic of early pandas. This behavior can be re-enabled globally by the mode.use_inf_as_null option:
In [11]: s = pd.Series([1.5, np.inf, 3.4, -np.inf])

In [12]: pd.isnull(s)

0    False
1    False
2    False
3    False
dtype: bool

In [13]: s.fillna(0)

0    1.500000
1         inf
2    3.400000
3        -inf
dtype: float64

In [14]: pd.set_option('use_inf_as_null', True)

In [15]: pd.isnull(s)

0    False
1     True
2    False
3     True
dtype: bool

In [16]: s.fillna(0)

0    1.5
1    0.0
2    3.4
3    0.0
dtype: float64

In [17]: pd.reset_option('use_inf_as_null')
  • Methods with the inplace option now all return None instead of the calling object. E.g. code written like df = df.fillna(0, inplace=True) may stop working. To fix, simply delete the unnecessary variable assignment.
  • pandas.merge no longer sorts the group keys (sort=False) by default. This was done for performance reasons: the group-key sorting is often one of the more expensive parts of the computation and is often unnecessary.
  • The default column names for a file with no header have been changed to the integers 0 through N - 1. This is to create consistency with the DataFrame constructor with no columns specified. The v0.9.0 behavior (names X0, X1, ...) can be reproduced by specifying prefix='X':
In [18]: data= 'a,b,c\n1,Yes,2\n3,No,4'

In [19]: print(data)
a,b,c
1,Yes,2
3,No,4

In [20]: pd.read_csv(StringIO(data), header=None)

   0    1  2
0  a    b  c
1  1  Yes  2
2  3   No  4

In [21]: pd.read_csv(StringIO(data), header=None, prefix='X')

  X0   X1 X2
0  a    b  c
1  1  Yes  2
2  3   No  4
  • Values like 'Yes' and 'No' are not interpreted as boolean by default, though this can be controlled by new true_values and false_values arguments:
In [22]: print(data)
a,b,c
1,Yes,2
3,No,4

In [23]: pd.read_csv(StringIO(data))

   a    b  c
0  1  Yes  2
1  3   No  4

In [24]: pd.read_csv(StringIO(data), true_values=['Yes'], false_values=['No'])

   a      b  c
0  1   True  2
1  3  False  4
  • The file parsers will not recognize non-string values arising from a converter function as NA if passed in the na_values argument. It’s better to do post-processing using the replace function instead.
  • Calling fillna on Series or DataFrame with no arguments is no longer valid code. You must either specify a fill value or an interpolation method:
In [25]: s = Series([np.nan, 1., 2., np.nan, 4])

In [26]: s

0   NaN
1     1
2     2
3   NaN
4     4
dtype: float64

In [27]: s.fillna(0)

0    0
1    1
2    2
3    0
4    4
dtype: float64

In [28]: s.fillna(method='pad')

0   NaN
1     1
2     2
3     2
4     4
dtype: float64

Convenience methods ffill and bfill have been added:

In [29]: s.ffill()

0   NaN
1     1
2     2
3     2
4     4
dtype: float64
  • Series.apply will now operate on a returned value from the applied function, that is itself a series, and possibly upcast the result to a DataFrame

    In [30]: def f(x):
       ....:     return Series([ x, x**2 ], index = ['x', 'x^2'])
       ....: 
    
    In [31]: s = Series(np.random.rand(5))
    
    In [32]: s
    
    0    0.245298
    1    0.735775
    2    0.162557
    3    0.278796
    4    0.898775
    dtype: float64
    
    In [33]: s.apply(f)
    
              x       x^2
    0  0.245298  0.060171
    1  0.735775  0.541365
    2  0.162557  0.026425
    3  0.278796  0.077727
    4  0.898775  0.807796
    
  • New API functions for working with pandas options (GH2097):

    • get_option / set_option - get/set the value of an option. Partial names are accepted. - reset_option - reset one or more options to their default value. Partial names are accepted. - describe_option - print a description of one or more options. When called with no arguments. print all registered options.

    Note: set_printoptions/ reset_printoptions are now deprecated (but functioning), the print options now live under “display.XYZ”. For example:

    In [34]: get_option("display.max_rows")
    60
    
  • to_string() methods now always return unicode strings (GH2224).

New features

Wide DataFrame Printing

Instead of printing the summary information, pandas now splits the string representation across multiple rows by default:

In [35]: wide_frame = DataFrame(randn(5, 16))

In [36]: wide_frame

         0         1         2         3         4         5         6   \
0 -0.246571 -0.669343  0.227154  0.372375  0.442205  0.768009 -1.395338   
1  0.706792 -0.289620 -1.379560  0.438201  3.665936 -0.178145  0.922878   
2  0.115510 -1.755125  1.077051  0.040440  1.255930 -0.348735  0.251467   
3 -0.205684 -1.500711  0.439094 -0.348664  0.509685  0.125035 -0.460265   
4 -1.222246 -1.698500 -1.707910 -0.850564 -2.190449  0.328881 -1.026750   
         7         8         9         10        11        12        13  \
0  0.819841  1.292347  0.338477  0.025694 -1.195347 -0.669205  0.172403   
1 -0.843746  1.492801  0.111974 -1.234326  1.043471 -0.147508 -0.060066   
2  1.125876  0.503278 -1.518080  1.249745 -0.397995 -0.999201  0.500484   
3 -0.253943 -2.083420  0.619208  0.130988 -1.060850 -0.861783  0.440666   
4 -0.096074 -1.205980 -0.564545  0.195360  1.570312 -1.229506 -1.545166   
         14        15  
0 -1.057219 -0.879778  
1 -1.501569 -0.961144  
2  1.460504  0.671222  
3 -0.599896  0.536874  
4 -0.196265 -0.734803  

The old behavior of printing out summary information can be achieved via the ‘expand_frame_repr’ print option:

In [37]: pd.set_option('expand_frame_repr', False)

In [38]: wide_frame

<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns (total 16 columns):
0     5  non-null values
1     5  non-null values
2     5  non-null values
3     5  non-null values
4     5  non-null values
5     5  non-null values
6     5  non-null values
7     5  non-null values
8     5  non-null values
9     5  non-null values
10    5  non-null values
11    5  non-null values
12    5  non-null values
13    5  non-null values
14    5  non-null values
15    5  non-null values
dtypes: float64(16)

The width of each line can be changed via ‘line_width’ (80 by default):

In [39]: pd.set_option('line_width', 40)

In [40]: wide_frame

         0         1         2   \
0 -0.246571 -0.669343  0.227154   
1  0.706792 -0.289620 -1.379560   
2  0.115510 -1.755125  1.077051   
3 -0.205684 -1.500711  0.439094   
4 -1.222246 -1.698500 -1.707910   
         3         4         5   \
0  0.372375  0.442205  0.768009   
1  0.438201  3.665936 -0.178145   
2  0.040440  1.255930 -0.348735   
3 -0.348664  0.509685  0.125035   
4 -0.850564 -2.190449  0.328881   
         6         7         8   \
0 -1.395338  0.819841  1.292347   
1  0.922878 -0.843746  1.492801   
2  0.251467  1.125876  0.503278   
3 -0.460265 -0.253943 -2.083420   
4 -1.026750 -0.096074 -1.205980   
         9         10        11  \
0  0.338477  0.025694 -1.195347   
1  0.111974 -1.234326  1.043471   
2 -1.518080  1.249745 -0.397995   
3  0.619208  0.130988 -1.060850   
4 -0.564545  0.195360  1.570312   
         12        13        14  \
0 -0.669205  0.172403 -1.057219   
1 -0.147508 -0.060066 -1.501569   
2 -0.999201  0.500484  1.460504   
3 -0.861783  0.440666 -0.599896   
4 -1.229506 -1.545166 -0.196265   
         15  
0 -0.879778  
1 -0.961144  
2  0.671222  
3  0.536874  
4 -0.734803  

Updated PyTables Support

Docs for PyTables Table format & several enhancements to the api. Here is a taste of what to expect.

In [41]: store = HDFStore('store.h5')

In [42]: df = DataFrame(randn(8, 3), index=date_range('1/1/2000', periods=8),
   ....:            columns=['A', 'B', 'C'])
   ....: 

In [43]: df

                   A         B         C
2000-01-01  0.682911  1.132498  0.603998
2000-01-02 -0.444686  1.000097 -0.849889
2000-01-03  0.963204  0.268821  0.860609
2000-01-04  0.645628 -0.517319 -0.242298
2000-01-05  0.262226  0.261196 -0.872165
2000-01-06  0.555224  0.464048 -0.502791
2000-01-07  0.481229 -0.729834  0.259358
2000-01-08 -0.659889  0.108813 -0.151509

# appending data frames
In [44]: df1 = df[0:4]

In [45]: df2 = df[4:]

In [46]: store.append('df', df1)

In [47]: store.append('df', df2)

In [48]: store

<class 'pandas.io.pytables.HDFStore'>
File path: store.h5
/df            frame_table  (typ->appendable,nrows->8,ncols->3,indexers->[index])

# selecting the entire store
In [49]: store.select('df')

                   A         B         C
2000-01-01  0.682911  1.132498  0.603998
2000-01-02 -0.444686  1.000097 -0.849889
2000-01-03  0.963204  0.268821  0.860609
2000-01-04  0.645628 -0.517319 -0.242298
2000-01-05  0.262226  0.261196 -0.872165
2000-01-06  0.555224  0.464048 -0.502791
2000-01-07  0.481229 -0.729834  0.259358
2000-01-08 -0.659889  0.108813 -0.151509
In [50]: wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
   ....:        major_axis=date_range('1/1/2000', periods=5),
   ....:        minor_axis=['A', 'B', 'C', 'D'])
   ....: 

In [51]: wp

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 5 (major_axis) x 4 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00
Minor_axis axis: A to D

# storing a panel
In [52]: store.append('wp',wp)

# selecting via A QUERY
In [53]: store.select('wp',
   ....:   [ Term('major_axis>20000102'), Term('minor_axis', '=', ['A','B']) ])
   ....: 

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 3 (major_axis) x 2 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2000-01-03 00:00:00 to 2000-01-05 00:00:00
Minor_axis axis: A to B

# removing data from tables
In [54]: store.remove('wp', Term('major_axis>20000103'))
8

In [55]: store.select('wp')

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 3 (major_axis) x 4 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-03 00:00:00
Minor_axis axis: A to D

# deleting a store
In [56]: del store['df']

In [57]: store

<class 'pandas.io.pytables.HDFStore'>
File path: store.h5
/wp            wide_table   (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])

Enhancements

  • added ability to hierarchical keys

    In [58]: store.put('foo/bar/bah', df)
    
    In [59]: store.append('food/orange', df)
    
    In [60]: store.append('food/apple',  df)
    
    In [61]: store
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: store.h5
    /wp                     wide_table   (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
    /food/apple             frame_table  (typ->appendable,nrows->8,ncols->3,indexers->[index])                 
    /food/orange            frame_table  (typ->appendable,nrows->8,ncols->3,indexers->[index])                 
    /foo/bar/bah            frame        (shape->[8,3])                                                        
    
    # remove all nodes under this level
    In [62]: store.remove('food')
    
    In [63]: store
    
    <class 'pandas.io.pytables.HDFStore'>
    File path: store.h5
    /wp                     wide_table   (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
    /foo/bar/bah            frame        (shape->[8,3])                                                        
    
  • added mixed-dtype support!

    In [64]: df['string'] = 'string'
    
    In [65]: df['int']    = 1
    
    In [66]: store.append('df',df)
    
    In [67]: df1 = store.select('df')
    
    In [68]: df1
    
                       A         B         C  string  int
    2000-01-01  0.682911  1.132498  0.603998  string    1
    2000-01-02 -0.444686  1.000097 -0.849889  string    1
    2000-01-03  0.963204  0.268821  0.860609  string    1
    2000-01-04  0.645628 -0.517319 -0.242298  string    1
    2000-01-05  0.262226  0.261196 -0.872165  string    1
    2000-01-06  0.555224  0.464048 -0.502791  string    1
    2000-01-07  0.481229 -0.729834  0.259358  string    1
    2000-01-08 -0.659889  0.108813 -0.151509  string    1
    
    In [69]: df1.get_dtype_counts()
    
    float64    3
    int64      1
    object     1
    dtype: int64
    
  • performance improvments on table writing

  • support for arbitrarily indexed dimensions

  • SparseSeries now has a density property (GH2384)

  • enable Series.str.strip/lstrip/rstrip methods to take an input argument to strip arbitrary characters (GH2411)

  • implement value_vars in melt to limit values to certain columns and add melt to pandas namespace (GH2412)

Bug Fixes

  • added Term method of specifying where conditions (GH1996).
  • del store['df'] now call store.remove('df') for store deletion
  • deleting of consecutive rows is much faster than before
  • min_itemsize parameter can be specified in table creation to force a minimum size for indexing columns (the previous implementation would set the column size based on the first append)
  • indexing support via create_table_index (requires PyTables >= 2.3) (GH698).
  • appending on a store would fail if the table was not first created via put
  • fixed issue with missing attributes after loading a pickled dataframe (GH2431)
  • minor change to select and remove: require a table ONLY if where is also provided (and not None)

Compatibility

0.10 of HDFStore is backwards compatible for reading tables created in a prior version of pandas, however, query terms using the prior (undocumented) methodology are unsupported. You must read in the entire file and write it out using the new format to take advantage of the updates.

N Dimensional Panels (Experimental)

Adding experimental support for Panel4D and factory functions to create n-dimensional named panels. Docs for NDim. Here is a taste of what to expect.

In [70]: p4d = Panel4D(randn(2, 2, 5, 4),
   ....:       labels=['Label1','Label2'],
   ....:       items=['Item1', 'Item2'],
   ....:       major_axis=date_range('1/1/2000', periods=5),
   ....:       minor_axis=['A', 'B', 'C', 'D'])
   ....: 

In [71]: p4d

<class 'pandas.core.panelnd.Panel4D'>
Dimensions: 2 (labels) x 2 (items) x 5 (major_axis) x 4 (minor_axis)
Labels axis: Label1 to Label2
Items axis: Item1 to Item2
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00
Minor_axis axis: A to D

See the full release notes or issue tracker on GitHub for a complete list.

v0.9.1 (November 14, 2012)

This is a bugfix release from 0.9.0 and includes several new features and enhancements along with a large number of bug fixes. The new features include by-column sort order for DataFrame and Series, improved NA handling for the rank method, masking functions for DataFrame, and intraday time-series filtering for DataFrame.

New features

  • Series.sort, DataFrame.sort, and DataFrame.sort_index can now be specified in a per-column manner to support multiple sort orders (GH928)

    In [1]: df = DataFrame(np.random.randint(0, 2, (6, 3)), columns=['A', 'B', 'C'])
    
    In [2]: df.sort(['A', 'B'], ascending=[1, 0])
    
       A  B  C
    4  0  0  1
    5  0  0  1
    2  1  1  0
    3  1  1  1
    0  1  0  0
    1  1  0  1
    
  • DataFrame.rank now supports additional argument values for the na_option parameter so missing values can be assigned either the largest or the smallest rank (GH1508, GH2159)

    In [3]: df = DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C'])
    
    In [4]: df.ix[2:4] = np.nan
    
    In [5]: df.rank()
    
        A   B   C
    0   3   3   2
    1   1   1   1
    2 NaN NaN NaN
    3 NaN NaN NaN
    4 NaN NaN NaN
    5   2   2   3
    
    In [6]: df.rank(na_option='top')
    
       A  B  C
    0  6  6  5
    1  4  4  4
    2  2  2  2
    3  2  2  2
    4  2  2  2
    5  5  5  6
    
    In [7]: df.rank(na_option='bottom')
    
       A  B  C
    0  3  3  2
    1  1  1  1
    2  5  5  5
    3  5  5  5
    4  5  5  5
    5  2  2  3
    
  • DataFrame has new where and mask methods to select values according to a given boolean mask (GH2109, GH2151)

    DataFrame currently supports slicing via a boolean vector the same length as the DataFrame (inside the []). The returned DataFrame has the same number of columns as the original, but is sliced on its index.

    In [8]: df = DataFrame(np.random.randn(5, 3), columns = ['A','B','C'])
    
    In [9]: df
    
              A         B         C
    0 -0.051513 -1.898514 -1.337939
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178 -0.248395
    3  0.394286 -1.560968  1.231331
    4  1.334209  0.886120  0.092576
    
    In [10]: df[df['A'] > 0]
    
              A         B         C
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178 -0.248395
    3  0.394286 -1.560968  1.231331
    4  1.334209  0.886120  0.092576
    

    If a DataFrame is sliced with a DataFrame based boolean condition (with the same size as the original DataFrame), then a DataFrame the same size (index and columns) as the original is returned, with elements that do not meet the boolean condition as NaN. This is accomplished via the new method DataFrame.where. In addition, where takes an optional other argument for replacement.

    In [11]: df[df>0]
    
              A         B         C
    0       NaN       NaN       NaN
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178       NaN
    3  0.394286       NaN  1.231331
    4  1.334209  0.886120  0.092576
    
    In [12]: df.where(df>0)
    
              A         B         C
    0       NaN       NaN       NaN
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178       NaN
    3  0.394286       NaN  1.231331
    4  1.334209  0.886120  0.092576
    
    In [13]: df.where(df>0,-df)
    
              A         B         C
    0  0.051513  1.898514  1.337939
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178  0.248395
    3  0.394286  1.560968  1.231331
    4  1.334209  0.886120  0.092576
    

    Furthermore, where now aligns the input boolean condition (ndarray or DataFrame), such that partial selection with setting is possible. This is analagous to partial setting via .ix (but on the contents rather than the axis labels)

    In [14]: df2 = df.copy()
    
    In [15]: df2[ df2[1:4] > 0 ] = 3
    
    In [16]: df2
    
              A         B         C
    0 -0.051513 -1.898514 -1.337939
    1  3.000000  3.000000  3.000000
    2  3.000000  3.000000 -0.248395
    3  3.000000 -1.560968  3.000000
    4  1.334209  0.886120  0.092576
    

    DataFrame.mask is the inverse boolean operation of where.

    In [17]: df.mask(df<=0)
    
              A         B         C
    0       NaN       NaN       NaN
    1  0.896659  0.630763  0.329113
    2  0.347033  0.551178       NaN
    3  0.394286       NaN  1.231331
    4  1.334209  0.886120  0.092576
    
  • Enable referencing of Excel columns by their column names (GH1936)

    In [18]: xl = ExcelFile('data/test.xls')
    
    In [19]: xl.parse('Sheet1', index_col=0, parse_dates=True,
       ....:          parse_cols='A:D')
       ....: 
    
                       A         B         C
    2000-01-03  0.980269  3.685731 -0.364217
    2000-01-04  1.047916 -0.041232 -0.161812
    2000-01-05  0.498581  0.731168 -0.537677
    2000-01-06  1.120202  1.567621  0.003641
    2000-01-07 -0.487094  0.571455 -1.611639
    2000-01-10  0.836649  0.246462  0.588543
    2000-01-11 -0.157161  1.340307  1.195778
    
  • Added option to disable pandas-style tick locators and formatters using series.plot(x_compat=True) or pandas.plot_params[‘x_compat’] = True (GH2205)

  • Existing TimeSeries methods at_time and between_time were added to DataFrame (GH2149)

  • DataFrame.dot can now accept ndarrays (GH2042)

  • DataFrame.drop now supports non-unique indexes (GH2101)

  • Panel.shift now supports negative periods (GH2164)

  • DataFrame now support unary ~ operator (GH2110)

API changes

  • Upsampling data with a PeriodIndex will result in a higher frequency TimeSeries that spans the original time window

    In [20]: prng = period_range('2012Q1', periods=2, freq='Q')
    
    In [21]: s = Series(np.random.randn(len(prng)), prng)
    
    In [22]: s.resample('M')
    
    2012-01   -1.276101
    2012-02         NaN
    2012-03         NaN
    2012-04    1.945410
    2012-05         NaN
    2012-06         NaN
    Freq: M, dtype: float64
    
  • Period.end_time now returns the last nanosecond in the time interval (GH2124, GH2125, GH1764)

    In [23]: p = Period('2012')
    
    In [24]: p.end_time
    Timestamp('2012-12-31 23:59:59.999999999', tz=None)
    
  • File parsers no longer coerce to float or bool for columns that have custom converters specified (GH2184)

    In [25]: data = 'A,B,C\n00001,001,5\n00002,002,6'
    
    In [26]: from cStringIO import StringIO
    
    In [27]: read_csv(StringIO(data), converters={'A' : lambda x: x.strip()})
    
           A  B  C
    0  00001  1  5
    1  00002  2  6
    

See the full release notes or issue tracker on GitHub for a complete list.

v0.9.0 (October 7, 2012)

This is a major release from 0.8.1 and includes several new features and enhancements along with a large number of bug fixes. New features include vectorized unicode encoding/decoding for Series.str, to_latex method to DataFrame, more flexible parsing of boolean values, and enabling the download of options data from Yahoo! Finance.

New features

  • Add encode and decode for unicode handling to vectorized string processing methods in Series.str (GH1706)
  • Add DataFrame.to_latex method (GH1735)
  • Add convenient expanding window equivalents of all rolling_* ops (GH1785)
  • Add Options class to pandas.io.data for fetching options data from Yahoo! Finance (GH1748, GH1739)
  • More flexible parsing of boolean values (Yes, No, TRUE, FALSE, etc) (GH1691, GH1295)
  • Add level parameter to Series.reset_index
  • TimeSeries.between_time can now select times across midnight (GH1871)
  • Series constructor can now handle generator as input (GH1679)
  • DataFrame.dropna can now take multiple axes (tuple/list) as input (GH924)
  • Enable skip_footer parameter in ExcelFile.parse (GH1843)

API changes

  • The default column names when header=None and no columns names passed to functions like read_csv has changed to be more Pythonic and amenable to attribute access:
In [1]: from StringIO import StringIO

In [2]: data = '0,0,1\n1,1,0\n0,1,0'

In [3]: df = read_csv(StringIO(data), header=None)

In [4]: df

   0  1  2
0  0  0  1
1  1  1  0
2  0  1  0
  • Creating a Series from another Series, passing an index, will cause reindexing to happen inside rather than treating the Series like an ndarray. Technically improper usages like Series(df[col1], index=df[col2]) that worked before “by accident” (this was never intended) will lead to all NA Series in some cases. To be perfectly clear:
In [5]: s1 = Series([1, 2, 3])

In [6]: s1

0    1
1    2
2    3
dtype: int64

In [7]: s2 = Series(s1, index=['foo', 'bar', 'baz'])

In [8]: s2

foo   NaN
bar   NaN
baz   NaN
dtype: float64
  • Deprecated day_of_year API removed from PeriodIndex, use dayofyear (GH1723)
  • Don’t modify NumPy suppress printoption to True at import time
  • The internal HDF5 data arrangement for DataFrames has been transposed. Legacy files will still be readable by HDFStore (GH1834, GH1824)
  • Legacy cruft removed: pandas.stats.misc.quantileTS
  • Use ISO8601 format for Period repr: monthly, daily, and on down (GH1776)
  • Empty DataFrame columns are now created as object dtype. This will prevent a class of TypeErrors that was occurring in code where the dtype of a column would depend on the presence of data or not (e.g. a SQL query having results) (GH1783)
  • Setting parts of DataFrame/Panel using ix now aligns input Series/DataFrame (GH1630)
  • first and last methods in GroupBy no longer drop non-numeric columns (GH1809)
  • Resolved inconsistencies in specifying custom NA values in text parser. na_values of type dict no longer override default NAs unless keep_default_na is set to false explicitly (GH1657)
  • DataFrame.dot will not do data alignment, and also work with Series (GH1915)

See the full release notes or issue tracker on GitHub for a complete list.

v0.8.1 (July 22, 2012)

This release includes a few new features, performance enhancements, and over 30 bug fixes from 0.8.0. New features include notably NA friendly string processing functionality and a series of new plot types and options.

New features

Performance improvements

  • Improved implementation of rolling min and max (thanks to Bottleneck !)
  • Add accelerated 'median' GroupBy option (GH1358)
  • Significantly improve the performance of parsing ISO8601-format date strings with DatetimeIndex or to_datetime (GH1571)
  • Improve the performance of GroupBy on single-key aggregations and use with Categorical types
  • Significant datetime parsing performance improvments

v0.8.0 (June 29, 2012)

This is a major release from 0.7.3 and includes extensive work on the time series handling and processing infrastructure as well as a great deal of new functionality throughout the library. It includes over 700 commits from more than 20 distinct authors. Most pandas 0.7.3 and earlier users should not experience any issues upgrading, but due to the migration to the NumPy datetime64 dtype, there may be a number of bugs and incompatibilities lurking. Lingering incompatibilities will be fixed ASAP in a 0.8.1 release if necessary. See the full release notes or issue tracker on GitHub for a complete list.

Support for non-unique indexes

All objects can now work with non-unique indexes. Data alignment / join operations work according to SQL join semantics (including, if application, index duplication in many-to-many joins)

NumPy datetime64 dtype and 1.6 dependency

Time series data are now represented using NumPy’s datetime64 dtype; thus, pandas 0.8.0 now requires at least NumPy 1.6. It has been tested and verified to work with the development version (1.7+) of NumPy as well which includes some significant user-facing API changes. NumPy 1.6 also has a number of bugs having to do with nanosecond resolution data, so I recommend that you steer clear of NumPy 1.6’s datetime64 API functions (though limited as they are) and only interact with this data using the interface that pandas provides.

See the end of the 0.8.0 section for a “porting” guide listing potential issues for users migrating legacy codebases from pandas 0.7 or earlier to 0.8.0.

Bug fixes to the 0.7.x series for legacy NumPy < 1.6 users will be provided as they arise. There will be no more further development in 0.7.x beyond bug fixes.

Time series changes and improvements

Note

With this release, legacy scikits.timeseries users should be able to port their code to use pandas.

Note

See documentation for overview of pandas timeseries API.

  • New datetime64 representation speeds up join operations and data alignment, reduces memory usage, and improve serialization / deserialization performance significantly over datetime.datetime
  • High performance and flexible resample method for converting from high-to-low and low-to-high frequency. Supports interpolation, user-defined aggregation functions, and control over how the intervals and result labeling are defined. A suite of high performance Cython/C-based resampling functions (including Open-High-Low-Close) have also been implemented.
  • Revamp of frequency aliases and support for frequency shortcuts like ‘15min’, or ‘1h30min’
  • New DatetimeIndex class supports both fixed frequency and irregular time series. Replaces now deprecated DateRange class
  • New PeriodIndex and Period classes for representing time spans and performing calendar logic, including the 12 fiscal quarterly frequencies <timeseries.quarterly>. This is a partial port of, and a substantial enhancement to, elements of the scikits.timeseries codebase. Support for conversion between PeriodIndex and DatetimeIndex
  • New Timestamp data type subclasses datetime.datetime, providing the same interface while enabling working with nanosecond-resolution data. Also provides easy time zone conversions.
  • Enhanced support for time zones. Add tz_convert and tz_lcoalize methods to TimeSeries and DataFrame. All timestamps are stored as UTC; Timestamps from DatetimeIndex objects with time zone set will be localized to localtime. Time zone conversions are therefore essentially free. User needs to know very little about pytz library now; only time zone names as as strings are required. Time zone-aware timestamps are equal if and only if their UTC timestamps match. Operations between time zone-aware time series with different time zones will result in a UTC-indexed time series.
  • Time series string indexing conveniences / shortcuts: slice years, year and month, and index values with strings
  • Enhanced time series plotting; adaptation of scikits.timeseries matplotlib-based plotting code
  • New date_range, bdate_range, and period_range factory functions
  • Robust frequency inference function infer_freq and inferred_freq property of DatetimeIndex, with option to infer frequency on construction of DatetimeIndex
  • to_datetime function efficiently parses array of strings to DatetimeIndex. DatetimeIndex will parse array or list of strings to datetime64
  • Optimized support for datetime64-dtype data in Series and DataFrame columns
  • New NaT (Not-a-Time) type to represent NA in timestamp arrays
  • Optimize Series.asof for looking up “as of” values for arrays of timestamps
  • Milli, Micro, Nano date offset objects
  • Can index time series with datetime.time objects to select all data at particular time of day (TimeSeries.at_time) or between two times (TimeSeries.between_time)
  • Add tshift method for leading/lagging using the frequency (if any) of the index, as opposed to a naive lead/lag using shift

Other new features

  • New cut and qcut functions (like R’s cut function) for computing a categorical variable from a continuous variable by binning values either into value-based (cut) or quantile-based (qcut) bins
  • Rename Factor to Categorical and add a number of usability features
  • Add limit argument to fillna/reindex
  • More flexible multiple function application in GroupBy, and can pass list (name, function) tuples to get result in particular order with given names
  • Add flexible replace method for efficiently substituting values
  • Enhanced read_csv/read_table for reading time series data and converting multiple columns to dates
  • Add comments option to parser functions: read_csv, etc.
  • Add :ref`dayfirst <io.dayfirst>` option to parser functions for parsing international DD/MM/YYYY dates
  • Allow the user to specify the CSV reader dialect to control quoting etc.
  • Handling thousands separators in read_csv to improve integer parsing.
  • Enable unstacking of multiple levels in one shot. Alleviate pivot_table bugs (empty columns being introduced)
  • Move to klib-based hash tables for indexing; better performance and less memory usage than Python’s dict
  • Add first, last, min, max, and prod optimized GroupBy functions
  • New ordered_merge function
  • Add flexible comparison instance methods eq, ne, lt, gt, etc. to DataFrame, Series
  • Improve scatter_matrix plotting function and add histogram or kernel density estimates to diagonal
  • Add ‘kde’ plot option for density plots
  • Support for converting DataFrame to R data.frame through rpy2
  • Improved support for complex numbers in Series and DataFrame
  • Add pct_change method to all data structures
  • Add max_colwidth configuration option for DataFrame console output
  • Interpolate Series values using index values
  • Can select multiple columns from GroupBy
  • Add update methods to Series/DataFrame for updating values in place
  • Add any and all method to DataFrame

New plotting methods

Series.plot now supports a secondary_y option:

In [1]: plt.figure()
<matplotlib.figure.Figure at 0x110777a90>

In [2]: fx['FR'].plot(style='g')
<matplotlib.axes.AxesSubplot at 0x110783050>

In [3]: fx['IT'].plot(style='k--', secondary_y=True)
<matplotlib.axes.AxesSubplot at 0x11079bb10>
_images/whatsnew_secondary_y.png

Vytautas Jancauskas, the 2012 GSOC participant, has added many new plot types. For example, 'kde' is a new option:

In [4]: s = Series(np.concatenate((np.random.randn(1000),
   ...:                            np.random.randn(1000) * 0.5 + 3)))
   ...: 

In [5]: plt.figure()
<matplotlib.figure.Figure at 0x110777f10>

In [6]: s.hist(normed=True, alpha=0.2)
<matplotlib.axes.AxesSubplot at 0x10f6b2c90>

In [7]: s.plot(kind='kde')
<matplotlib.axes.AxesSubplot at 0x10f6b2c90>
_images/whatsnew_kde.png

See the plotting page for much more.

Other API changes

  • Deprecation of offset, time_rule, and timeRule arguments names in time series functions. Warnings will be printed until pandas 0.9 or 1.0.

Potential porting issues for pandas <= 0.7.3 users

The major change that may affect you in pandas 0.8.0 is that time series indexes use NumPy’s datetime64 data type instead of dtype=object arrays of Python’s built-in datetime.datetime objects. DateRange has been replaced by DatetimeIndex but otherwise behaved identically. But, if you have code that converts DateRange or Index objects that used to contain datetime.datetime values to plain NumPy arrays, you may have bugs lurking with code using scalar values because you are handing control over to NumPy:

In [8]: import datetime

In [9]: rng = date_range('1/1/2000', periods=10)

In [10]: rng[5]
Timestamp('2000-01-06 00:00:00', tz=None)

In [11]: isinstance(rng[5], datetime.datetime)
True

In [12]: rng_asarray = np.asarray(rng)

In [13]: scalar_val = rng_asarray[5]

In [14]: type(scalar_val)
numpy.datetime64

pandas’s Timestamp object is a subclass of datetime.datetime that has nanosecond support (the nanosecond field store the nanosecond value between 0 and 999). It should substitute directly into any code that used datetime.datetime values before. Thus, I recommend not casting DatetimeIndex to regular NumPy arrays.

If you have code that requires an array of datetime.datetime objects, you have a couple of options. First, the asobject property of DatetimeIndex produces an array of Timestamp objects:

In [15]: stamp_array = rng.asobject

In [16]: stamp_array
Index([2000-01-01 00:00:00, 2000-01-02 00:00:00, 2000-01-03 00:00:00, 2000-01-04 00:00:00, 2000-01-05 00:00:00, 2000-01-06 00:00:00, 2000-01-07 00:00:00, 2000-01-08 00:00:00, 2000-01-09 00:00:00, 2000-01-10 00:00:00], dtype='object')

In [17]: stamp_array[5]
Timestamp('2000-01-06 00:00:00', tz=None)

To get an array of proper datetime.datetime objects, use the to_pydatetime method:

In [18]: dt_array = rng.to_pydatetime()

In [19]: dt_array

array([datetime.datetime(2000, 1, 1, 0, 0),
       datetime.datetime(2000, 1, 2, 0, 0),
       datetime.datetime(2000, 1, 3, 0, 0),
       datetime.datetime(2000, 1, 4, 0, 0),
       datetime.datetime(2000, 1, 5, 0, 0),
       datetime.datetime(2000, 1, 6, 0, 0),
       datetime.datetime(2000, 1, 7, 0, 0),
       datetime.datetime(2000, 1, 8, 0, 0),
       datetime.datetime(2000, 1, 9, 0, 0),
       datetime.datetime(2000, 1, 10, 0, 0)], dtype=object)

In [20]: dt_array[5]
datetime.datetime(2000, 1, 6, 0, 0)

matplotlib knows how to handle datetime.datetime but not Timestamp objects. While I recommend that you plot time series using TimeSeries.plot, you can either use to_pydatetime or register a converter for the Timestamp type. See matplotlib documentation for more on this.

Warning

There are bugs in the user-facing API with the nanosecond datetime64 unit in NumPy 1.6. In particular, the string version of the array shows garbage values, and conversion to dtype=object is similarly broken.

In [21]: rng = date_range('1/1/2000', periods=10)

In [22]: rng

<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 00:00:00, ..., 2000-01-10 00:00:00]
Length: 10, Freq: D, Timezone: None

In [23]: np.asarray(rng)

array(['1999-12-31T19:00:00.000000000-0500',
       '2000-01-01T19:00:00.000000000-0500',
       '2000-01-02T19:00:00.000000000-0500',
       '2000-01-03T19:00:00.000000000-0500',
       '2000-01-04T19:00:00.000000000-0500',
       '2000-01-05T19:00:00.000000000-0500',
       '2000-01-06T19:00:00.000000000-0500',
       '2000-01-07T19:00:00.000000000-0500',
       '2000-01-08T19:00:00.000000000-0500',
       '2000-01-09T19:00:00.000000000-0500'], dtype='datetime64[ns]')

In [24]: converted = np.asarray(rng, dtype=object)

In [25]: converted[5]
947116800000000000L

Trust me: don’t panic. If you are using NumPy 1.6 and restrict your interaction with datetime64 values to pandas’s API you will be just fine. There is nothing wrong with the data-type (a 64-bit integer internally); all of the important data processing happens in pandas and is heavily tested. I strongly recommend that you do not work directly with datetime64 arrays in NumPy 1.6 and only use the pandas API.

Support for non-unique indexes: In the latter case, you may have code inside a try:... catch: block that failed due to the index not being unique. In many cases it will no longer fail (some method like append still check for uniqueness unless disabled). However, all is not lost: you can inspect index.is_unique and raise an exception explicitly if it is False or go to a different code branch.

v.0.7.3 (April 12, 2012)

This is a minor release from 0.7.2 and fixes many minor bugs and adds a number of nice new features. There are also a couple of API changes to note; these should not affect very many users, and we are inclined to call them “bug fixes” even though they do constitute a change in behavior. See the full release notes or issue tracker on GitHub for a complete list.

New features

from pandas.tools.plotting import scatter_matrix
scatter_matrix(df, alpha=0.2)
_images/scatter_matrix_kde.png
  • Add stacked argument to Series and DataFrame’s plot method for stacked bar plots.
df.plot(kind='bar', stacked=True)
_images/bar_plot_stacked_ex.png
df.plot(kind='barh', stacked=True)
_images/barh_plot_stacked_ex.png
  • Add log x and y scaling options to DataFrame.plot and Series.plot
  • Add kurt methods to Series and DataFrame for computing kurtosis

NA Boolean Comparison API Change

Reverted some changes to how NA values (represented typically as NaN or None) are handled in non-numeric Series:

In [1]: series = Series(['Steve', np.nan, 'Joe'])

In [2]: series == 'Steve'

0     True
1    False
2    False
dtype: bool

In [3]: series != 'Steve'

0    False
1     True
2     True
dtype: bool

In comparisons, NA / NaN will always come through as False except with != which is True. Be very careful with boolean arithmetic, especially negation, in the presence of NA data. You may wish to add an explicit NA filter into boolean array operations if you are worried about this:

In [4]: mask = series == 'Steve'

In [5]: series[mask & series.notnull()]

0    Steve
dtype: object

While propagating NA in comparisons may seem like the right behavior to some users (and you could argue on purely technical grounds that this is the right thing to do), the evaluation was made that propagating NA everywhere, including in numerical arrays, would cause a large amount of problems for users. Thus, a “practicality beats purity” approach was taken. This issue may be revisited at some point in the future.

Other API Changes

When calling apply on a grouped Series, the return value will also be a Series, to be more consistent with the groupby behavior with DataFrame:

In [1]: df = DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
   ...:                     'foo', 'bar', 'foo', 'foo'],
   ...:                 'B' : ['one', 'one', 'two', 'three',
   ...:                        'two', 'two', 'one', 'three'],
   ...:                 'C' : np.random.randn(8), 'D' : np.random.randn(8)})
   ...: 

In [2]: df

     A      B         C         D
0  foo    one  0.417943  0.219884
1  bar    one  1.922130  0.371782
2  foo    two  0.027517  0.894153
3  bar  three -0.714216 -1.438071
4  foo    two  0.051235 -1.050134
5  bar    two -0.678307  1.623200
6  foo    one  0.813668  0.578826
7  foo  three  0.261304 -1.876279

In [3]: grouped = df.groupby('A')['C']

In [4]: grouped.describe()

A         
bar  count    3.000000
     mean     0.176536
     std      1.511836
     min     -0.714216
     25%     -0.696262
     50%     -0.678307
     75%      0.621911
     max      1.922130
foo  count    5.000000
     mean     0.314333
     std      0.321857
     min      0.027517
     25%      0.051235
     50%      0.261304
     75%      0.417943
     max      0.813668
dtype: float64

In [5]: grouped.apply(lambda x: x.order()[-2:]) # top 2 values

A     
bar  5   -0.678307
     1    1.922130
foo  0    0.417943
     6    0.813668
dtype: float64

v.0.7.2 (March 16, 2012)

This release targets bugs in 0.7.1, and adds a few minor features.

New features

  • Add additional tie-breaking methods in DataFrame.rank (GH874)
  • Add ascending parameter to rank in Series, DataFrame (GH875)
  • Add coerce_float option to DataFrame.from_records (GH893)
  • Add sort_columns parameter to allow unsorted plots (GH918)
  • Enable column access via attributes on GroupBy (GH882)
  • Can pass dict of values to DataFrame.fillna (GH661)
  • Can select multiple hierarchical groups by passing list of values in .ix (GH134)
  • Add axis option to DataFrame.fillna (GH174)
  • Add level keyword to drop for dropping values from a level (GH159)

Performance improvements

  • Use khash for Series.value_counts, add raw function to algorithms.py (GH861)
  • Intercept __builtin__.sum in groupby (GH885)

v.0.7.1 (February 29, 2012)

This release includes a few new features and addresses over a dozen bugs in 0.7.0.

New features

  • Add to_clipboard function to pandas namespace for writing objects to the system clipboard (GH774)
  • Add itertuples method to DataFrame for iterating through the rows of a dataframe as tuples (GH818)
  • Add ability to pass fill_value and method to DataFrame and Series align method (GH806, GH807)
  • Add fill_value option to reindex, align methods (GH784)
  • Enable concat to produce DataFrame from Series (GH787)
  • Add between method to Series (GH802)
  • Add HTML representation hook to DataFrame for the IPython HTML notebook (GH773)
  • Support for reading Excel 2007 XML documents using openpyxl

Performance improvements

  • Improve performance and memory usage of fillna on DataFrame
  • Can concatenate a list of Series along axis=1 to obtain a DataFrame (GH787)

v.0.7.0 (February 9, 2012)

New features

  • New unified merge function for efficiently performing full gamut of database / relational-algebra operations. Refactored existing join methods to use the new infrastructure, resulting in substantial performance gains (GH220, GH249, GH267)
  • New unified concatenation function for concatenating Series, DataFrame or Panel objects along an axis. Can form union or intersection of the other axes. Improves performance of Series.append and DataFrame.append (GH468, GH479, GH273)
  • Can pass multiple DataFrames to DataFrame.append to concatenate (stack) and multiple Series to Series.append too
  • Can pass list of dicts (e.g., a list of JSON objects) to DataFrame constructor (GH526)
  • You can now set multiple columns in a DataFrame via __getitem__, useful for transformation (GH342)
  • Handle differently-indexed output values in DataFrame.apply (GH498)
In [1]: df = DataFrame(randn(10, 4))

In [2]: df.apply(lambda x: x.describe())

               0          1          2          3
count  10.000000  10.000000  10.000000  10.000000
mean   -0.604375   0.063176  -0.188724   0.497182
std     1.124708   1.068386   0.791930   0.584394
min    -2.045602  -2.135143  -1.551202  -0.310990
25%    -1.703149  -0.403042  -0.800661   0.284284
50%    -0.391449   0.105153  -0.081550   0.426774
75%     0.044484   0.973346   0.404616   0.676053
max     1.226960   1.201784   0.773630   1.584370
  • Add reorder_levels method to Series and DataFrame (GH534)
  • Add dict-like get function to DataFrame and Panel (GH521)
  • Add DataFrame.iterrows method for efficiently iterating through the rows of a DataFrame
  • Add DataFrame.to_panel with code adapted from LongPanel.to_long
  • Add reindex_axis method added to DataFrame
  • Add level option to binary arithmetic functions on DataFrame and Series
  • Add level option to the reindex and align methods on Series and DataFrame for broadcasting values across a level (GH542, GH552, others)
  • Add attribute-based item access to Panel and add IPython completion (GH563)
  • Add logy option to Series.plot for log-scaling on the Y axis
  • Add index and header options to DataFrame.to_string
  • Can pass multiple DataFrames to DataFrame.join to join on index (GH115)
  • Can pass multiple Panels to Panel.join (GH115)
  • Added justify argument to DataFrame.to_string to allow different alignment of column headers
  • Add sort option to GroupBy to allow disabling sorting of the group keys for potential speedups (GH595)
  • Can pass MaskedArray to Series constructor (GH563)
  • Add Panel item access via attributes and IPython completion (GH554)
  • Implement DataFrame.lookup, fancy-indexing analogue for retrieving values given a sequence of row and column labels (GH338)
  • Can pass a list of functions to aggregate with groupby on a DataFrame, yielding an aggregated result with hierarchical columns (GH166)
  • Can call cummin and cummax on Series and DataFrame to get cumulative minimum and maximum, respectively (GH647)
  • value_range added as utility function to get min and max of a dataframe (GH288)
  • Added encoding argument to read_csv, read_table, to_csv and from_csv for non-ascii text (GH717)
  • Added abs method to pandas objects
  • Added crosstab function for easily computing frequency tables
  • Added isin method to index objects
  • Added level argument to xs method of DataFrame.

API Changes to integer indexing

One of the potentially riskiest API changes in 0.7.0, but also one of the most important, was a complete review of how integer indexes are handled with regard to label-based indexing. Here is an example:

In [3]: s = Series(randn(10), index=range(0, 20, 2))

In [4]: s

0    -1.969892
2     0.742913
4     0.049707
6     1.075398
8    -1.252423
10    0.302257
12    0.367931
14   -0.692332
16   -0.011834
18   -0.794666
dtype: float64

In [5]: s[0]
-1.9698924296765941

In [6]: s[2]
0.74291256418515372

In [7]: s[4]
0.049707018087011619

This is all exactly identical to the behavior before. However, if you ask for a key not contained in the Series, in versions 0.6.1 and prior, Series would fall back on a location-based lookup. This now raises a KeyError:

In [2]: s[1]
KeyError: 1

This change also has the same impact on DataFrame:

In [3]: df = DataFrame(randn(8, 4), index=range(0, 16, 2))

In [4]: df
    0        1       2       3
0   0.88427  0.3363 -0.1787  0.03162
2   0.14451 -0.1415  0.2504  0.58374
4  -1.44779 -0.9186 -1.4996  0.27163
6  -0.26598 -2.4184 -0.2658  0.11503
8  -0.58776  0.3144 -0.8566  0.61941
10  0.10940 -0.7175 -1.0108  0.47990
12 -1.16919 -0.3087 -0.6049 -0.43544
14 -0.07337  0.3410  0.0424 -0.16037

In [5]: df.ix[3]
KeyError: 3

In order to support purely integer-based indexing, the following methods have been added:

Method Description
Series.iget_value(i) Retrieve value stored at location i
Series.iget(i) Alias for iget_value
DataFrame.irow(i) Retrieve the i-th row
DataFrame.icol(j) Retrieve the j-th column
DataFrame.iget_value(i, j) Retrieve the value at row i and column j

API tweaks regarding label-based slicing

Label-based slicing using ix now requires that the index be sorted (monotonic) unless both the start and endpoint are contained in the index:

In [8]: s = Series(randn(6), index=list('gmkaec'))

In [9]: s

g    1.116458
m   -0.927441
k    1.221174
a   -0.221841
e    0.802310
c    1.695657
dtype: float64

Then this is OK:

In [10]: s.ix['k':'e']

k    1.221174
a   -0.221841
e    0.802310
dtype: float64

But this is not:

In [12]: s.ix['b':'h']
KeyError 'b'

If the index had been sorted, the “range selection” would have been possible:

In [11]: s2 = s.sort_index()

In [12]: s2

a   -0.221841
c    1.695657
e    0.802310
g    1.116458
k    1.221174
m   -0.927441
dtype: float64

In [13]: s2.ix['b':'h']

c    1.695657
e    0.802310
g    1.116458
dtype: float64

Changes to Series [] operator

As as notational convenience, you can pass a sequence of labels or a label slice to a Series when getting and setting values via [] (i.e. the __getitem__ and __setitem__ methods). The behavior will be the same as passing similar input to ix except in the case of integer indexing:

In [14]: s = Series(randn(6), index=list('acegkm'))

In [15]: s

a    3.052986
c    0.057296
e   -0.318653
g    1.303301
k    0.702943
m    0.331899
dtype: float64

In [16]: s[['m', 'a', 'c', 'e']]

m    0.331899
a    3.052986
c    0.057296
e   -0.318653
dtype: float64

In [17]: s['b':'l']

c    0.057296
e   -0.318653
g    1.303301
k    0.702943
dtype: float64

In [18]: s['c':'k']

c    0.057296
e   -0.318653
g    1.303301
k    0.702943
dtype: float64

In the case of integer indexes, the behavior will be exactly as before (shadowing ndarray):

In [19]: s = Series(randn(6), index=range(0, 12, 2))

In [20]: s[[4, 0, 2]]

4    1.337964
0   -1.136540
2   -0.238860
dtype: float64

In [21]: s[1:5]

2   -0.238860
4    1.337964
6   -0.670955
8   -0.033300
dtype: float64

If you wish to do indexing with sequences and slicing on an integer index with label semantics, use ix.

Other API Changes

  • The deprecated LongPanel class has been completely removed
  • If Series.sort is called on a column of a DataFrame, an exception will now be raised. Before it was possible to accidentally mutate a DataFrame’s column by doing df[col].sort() instead of the side-effect free method df[col].order() (GH316)
  • Miscellaneous renames and deprecations which will (harmlessly) raise FutureWarning
  • drop added as an optional parameter to DataFrame.reset_index (GH699)

Performance improvements

  • Cythonized GroupBy aggregations no longer presort the data, thus achieving a significant speedup (GH93). GroupBy aggregations with Python functions significantly sped up by clever manipulation of the ndarray data type in Cython (GH496).
  • Better error message in DataFrame constructor when passed column labels don’t match data (GH497)
  • Substantially improve performance of multi-GroupBy aggregation when a Python function is passed, reuse ndarray object in Cython (GH496)
  • Can store objects indexed by tuples and floats in HDFStore (GH492)
  • Don’t print length by default in Series.to_string, add length option (GH489)
  • Improve Cython code for multi-groupby to aggregate without having to sort the data (GH93)
  • Improve MultiIndex reindexing speed by storing tuples in the MultiIndex, test for backwards unpickling compatibility
  • Improve column reindexing performance by using specialized Cython take function
  • Further performance tweaking of Series.__getitem__ for standard use cases
  • Avoid Index dict creation in some cases (i.e. when getting slices, etc.), regression from prior versions
  • Friendlier error message in setup.py if NumPy not installed
  • Use common set of NA-handling operations (sum, mean, etc.) in Panel class also (GH536)
  • Default name assignment when calling reset_index on DataFrame with a regular (non-hierarchical) index (GH476)
  • Use Cythonized groupers when possible in Series/DataFrame stat ops with level parameter passed (GH545)
  • Ported skiplist data structure to C to speed up rolling_median by about 5-10x in most typical use cases (GH374)

v.0.6.1 (December 13, 2011)

New features

Performance improvements

  • Improve memory usage of DataFrame.describe (do not copy data unnecessarily) (PR #425)
  • Optimize scalar value lookups in the general case by 25% or more in Series and DataFrame
  • Fix performance regression in cross-sectional count in DataFrame, affecting DataFrame.dropna speed
  • Column deletion in DataFrame copies no data (computes views on blocks) (GH #158)

v.0.6.0 (November 25, 2011)

New Features

  • Added melt function to pandas.core.reshape
  • Added level parameter to group by level in Series and DataFrame descriptive statistics (GH313)
  • Added head and tail methods to Series, analogous to to DataFrame (GH296)
  • Added Series.isin function which checks if each value is contained in a passed sequence (GH289)
  • Added float_format option to Series.to_string
  • Added skip_footer (GH291) and converters (GH343) options to read_csv and read_table
  • Added drop_duplicates and duplicated functions for removing duplicate DataFrame rows and checking for duplicate rows, respectively (GH319)
  • Implemented operators ‘&’, ‘|’, ‘^’, ‘-‘ on DataFrame (GH347)
  • Added Series.mad, mean absolute deviation
  • Added QuarterEnd DateOffset (GH321)
  • Added dot to DataFrame (GH65)
  • Added orient option to Panel.from_dict (GH359, GH301)
  • Added orient option to DataFrame.from_dict
  • Added passing list of tuples or list of lists to DataFrame.from_records (GH357)
  • Added multiple levels to groupby (GH103)
  • Allow multiple columns in by argument of DataFrame.sort_index (GH92, GH362)
  • Added fast get_value and put_value methods to DataFrame (GH360)
  • Added cov instance methods to Series and DataFrame (GH194, GH362)
  • Added kind='bar' option to DataFrame.plot (GH348)
  • Added idxmin and idxmax to Series and DataFrame (GH286)
  • Added read_clipboard function to parse DataFrame from clipboard (GH300)
  • Added nunique function to Series for counting unique elements (GH297)
  • Made DataFrame constructor use Series name if no columns passed (GH373)
  • Support regular expressions in read_table/read_csv (GH364)
  • Added DataFrame.to_html for writing DataFrame to HTML (GH387)
  • Added support for MaskedArray data in DataFrame, masked values converted to NaN (GH396)
  • Added DataFrame.boxplot function (GH368)
  • Can pass extra args, kwds to DataFrame.apply (GH376)
  • Implement DataFrame.join with vector on argument (GH312)
  • Added legend boolean flag to DataFrame.plot (GH324)
  • Can pass multiple levels to stack and unstack (GH370)
  • Can pass multiple values columns to pivot_table (GH381)
  • Use Series name in GroupBy for result index (GH363)
  • Added raw option to DataFrame.apply for performance if only need ndarray (GH309)
  • Added proper, tested weighted least squares to standard and panel OLS (GH303)

Performance Enhancements

  • VBENCH Cythonized cache_readonly, resulting in substantial micro-performance enhancements throughout the codebase (GH361)
  • VBENCH Special Cython matrix iterator for applying arbitrary reduction operations with 3-5x better performance than np.apply_along_axis (GH309)
  • VBENCH Improved performance of MultiIndex.from_tuples
  • VBENCH Special Cython matrix iterator for applying arbitrary reduction operations
  • VBENCH + DOCUMENT Add raw option to DataFrame.apply for getting better performance when
  • VBENCH Faster cythonized count by level in Series and DataFrame (GH341)
  • VBENCH? Significant GroupBy performance enhancement with multiple keys with many “empty” combinations
  • VBENCH New Cython vectorized function map_infer speeds up Series.apply and Series.map significantly when passed elementwise Python function, motivated by (GH355)
  • VBENCH Significantly improved performance of Series.order, which also makes np.unique called on a Series faster (GH327)
  • VBENCH Vastly improved performance of GroupBy on axes with a MultiIndex (GH299)

v.0.5.0 (October 24, 2011)

New Features

  • Added DataFrame.align method with standard join options
  • Added parse_dates option to read_csv and read_table methods to optionally try to parse dates in the index columns
  • Added nrows, chunksize, and iterator arguments to read_csv and read_table. The last two return a new TextParser class capable of lazily iterating through chunks of a flat file (GH242)
  • Added ability to join on multiple columns in DataFrame.join (GH214)
  • Added private _get_duplicates function to Index for identifying duplicate values more easily (ENH5c)
  • Added column attribute access to DataFrame.
  • Added Python tab completion hook for DataFrame columns. (GH233, GH230)
  • Implemented Series.describe for Series containing objects (GH241)
  • Added inner join option to DataFrame.join when joining on key(s) (GH248)
  • Implemented selecting DataFrame columns by passing a list to __getitem__ (GH253)
  • Implemented & and | to intersect / union Index objects, respectively (GH261)
  • Added pivot_table convenience function to pandas namespace (GH234)
  • Implemented Panel.rename_axis function (GH243)
  • DataFrame will show index level names in console output (GH334)
  • Implemented Panel.take
  • Added set_eng_float_format for alternate DataFrame floating point string formatting (ENH61)
  • Added convenience set_index function for creating a DataFrame index from its existing columns
  • Implemented groupby hierarchical index level name (GH223)
  • Added support for different delimiters in DataFrame.to_csv (GH244)
  • TODO: DOCS ABOUT TAKE METHODS

Performance Enhancements

  • VBENCH Major performance improvements in file parsing functions read_csv and read_table
  • VBENCH Added Cython function for converting tuples to ndarray very fast. Speeds up many MultiIndex-related operations
  • VBENCH Refactored merging / joining code into a tidy class and disabled unnecessary computations in the float/object case, thus getting about 10% better performance (GH211)
  • VBENCH Improved speed of DataFrame.xs on mixed-type DataFrame objects by about 5x, regression from 0.3.0 (GH215)
  • VBENCH With new DataFrame.align method, speeding up binary operations between differently-indexed DataFrame objects by 10-25%.
  • VBENCH Significantly sped up conversion of nested dict into DataFrame (GH212)
  • VBENCH Significantly speed up DataFrame __repr__ and count on large mixed-type DataFrame objects

v.0.4.3 through v0.4.1 (September 25 - October 9, 2011)

New Features

  • Added Python 3 support using 2to3 (GH200)
  • Added name attribute to Series, now prints as part of Series.__repr__
  • Added instance methods isnull and notnull to Series (GH209, GH203)
  • Added Series.align method for aligning two series with choice of join method (ENH56)
  • Added method get_level_values to MultiIndex (GH188)
  • Set values in mixed-type DataFrame objects via .ix indexing attribute (GH135)
  • Added new DataFrame methods get_dtype_counts and property dtypes (ENHdc)
  • Added ignore_index option to DataFrame.append to stack DataFrames (ENH1b)
  • read_csv tries to sniff delimiters using csv.Sniffer (GH146)
  • read_csv can read multiple columns into a MultiIndex; DataFrame’s to_csv method writes out a corresponding MultiIndex (GH151)
  • DataFrame.rename has a new copy parameter to rename a DataFrame in place (ENHed)
  • Enable unstacking by name (GH142)
  • Enable sortlevel to work by level (GH141)

Performance Enhancements

  • Altered binary operations on differently-indexed SparseSeries objects to use the integer-based (dense) alignment logic which is faster with a larger number of blocks (GH205)
  • Wrote faster Cython data alignment / merging routines resulting in substantial speed increases
  • Improved performance of isnull and notnull, a regression from v0.3.0 (GH187)
  • Refactored code related to DataFrame.join so that intermediate aligned copies of the data in each DataFrame argument do not need to be created. Substantial performance increases result (GH176)
  • Substantially improved performance of generic Index.intersection and Index.union
  • Implemented BlockManager.take resulting in significantly faster take performance on mixed-type DataFrame objects (GH104)
  • Improved performance of Series.sort_index
  • Significant groupby performance enhancement: removed unnecessary integrity checks in DataFrame internals that were slowing down slicing operations to retrieve groups
  • Optimized _ensure_index function resulting in performance savings in type-checking Index objects
  • Wrote fast time series merging / joining methods in Cython. Will be integrated later into DataFrame.join and related functions