Table Of Contents


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.18.1 (May 3, 2016)

This is a minor bug-fix release from 0.18.0 and includes a large number of bug fixes along with several new features, enhancements, and performance improvements. We recommend that all users upgrade to this version.

Highlights include:

  • .groupby(...) has been enhanced to provide convenient syntax when working with .rolling(..), .expanding(..) and .resample(..) per group, see here
  • pd.to_datetime() has gained the ability to assemble dates from a DataFrame, see here
  • Method chaining improvements, see here.
  • Custom business hour offset, see here.
  • Many bug fixes in the handling of sparse, see here
  • Expanded the Tutorials section with a feature on modern pandas, courtesy of @TomAugsburger. (GH13045).

New features

Custom Business Hour

The CustomBusinessHour is a mixture of BusinessHour and CustomBusinessDay which allows you to specify arbitrary holidays. For details, see Custom Business Hour (GH11514)

In [1]: from pandas.tseries.offsets import CustomBusinessHour

In [2]: from import USFederalHolidayCalendar

In [3]: bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())

Friday before MLK Day

In [4]: dt = datetime(2014, 1, 17, 15)

In [5]: dt + bhour_us
Out[5]: Timestamp('2014-01-17 16:00:00')

Tuesday after MLK Day (Monday is skipped because it’s a holiday)

In [6]: dt + bhour_us * 2
Out[6]: Timestamp('2014-01-21 09:00:00')

.groupby(..) syntax with window and resample operations

.groupby(...) has been enhanced to provide convenient syntax when working with .rolling(..), .expanding(..) and .resample(..) per group, see (GH12486, GH12738).

You can now use .rolling(..) and .expanding(..) as methods on groupbys. These return another deferred object (similar to what .rolling() and .expanding() do on ungrouped pandas objects). You can then operate on these RollingGroupby objects in a similar manner.

Previously you would have to do this to get a rolling window mean per-group:

In [7]: df = pd.DataFrame({'A': [1] * 20 + [2] * 12 + [3] * 8,
   ...:                    'B': np.arange(40)})

In [8]: df
    A   B
0   1   0
1   1   1
2   1   2
3   1   3
4   1   4
5   1   5
6   1   6
.. ..  ..
33  3  33
34  3  34
35  3  35
36  3  36
37  3  37
38  3  38
39  3  39

[40 rows x 2 columns]
In [9]: df.groupby('A').apply(lambda x: x.rolling(4).B.mean())
1  0      NaN
   1      NaN
   2      NaN
   3      1.5
   4      2.5
   5      3.5
   6      4.5
3  33     NaN
   34     NaN
   35    33.5
   36    34.5
   37    35.5
   38    36.5
   39    37.5
Name: B, dtype: float64

Now you can do:

In [10]: df.groupby('A').rolling(4).B.mean()
1  0      NaN
   1      NaN
   2      NaN
   3      1.5
   4      2.5
   5      3.5
   6      4.5
3  33     NaN
   34     NaN
   35    33.5
   36    34.5
   37    35.5
   38    36.5
   39    37.5
Name: B, dtype: float64

For .resample(..) type of operations, previously you would have to:

In [11]: df = pd.DataFrame({'date': pd.date_range(start='2016-01-01',
   ....:                                          periods=4,
   ....:                                          freq='W'),
   ....:                    'group': [1, 1, 2, 2],
   ....:                    'val': [5, 6, 7, 8]}).set_index('date')

In [12]: df
            group  val
2016-01-03      1    5
2016-01-10      1    6
2016-01-17      2    7
2016-01-24      2    8
In [13]: df.groupby('group').apply(lambda x: x.resample('1D').ffill())
                  group  val
group date                  
1     2016-01-03      1    5
      2016-01-04      1    5
      2016-01-05      1    5
      2016-01-06      1    5
      2016-01-07      1    5
      2016-01-08      1    5
      2016-01-09      1    5
...                 ...  ...
2     2016-01-18      2    7
      2016-01-19      2    7
      2016-01-20      2    7
      2016-01-21      2    7
      2016-01-22      2    7
      2016-01-23      2    7
      2016-01-24      2    8

[16 rows x 2 columns]

Now you can do:

In [14]: df.groupby('group').resample('1D').ffill()
                  group  val
group date                  
1     2016-01-03      1    5
      2016-01-04      1    5
      2016-01-05      1    5
      2016-01-06      1    5
      2016-01-07      1    5
      2016-01-08      1    5
      2016-01-09      1    5
...                 ...  ...
2     2016-01-18      2    7
      2016-01-19      2    7
      2016-01-20      2    7
      2016-01-21      2    7
      2016-01-22      2    7
      2016-01-23      2    7
      2016-01-24      2    8

[16 rows x 2 columns]

Method chaininng improvements

The following methods / indexers now accept a callable. It is intended to make these more useful in method chains, see the documentation. (GH11485, GH12533)

  • .where() and .mask()
  • .loc[], iloc[] and .ix[]
  • [] indexing
.where() and .mask()

These can accept a callable for the condition and other arguments.

In [15]: df = pd.DataFrame({'A': [1, 2, 3],
   ....:                    'B': [4, 5, 6],
   ....:                    'C': [7, 8, 9]})

In [16]: df.where(lambda x: x > 4, lambda x: x + 10)
    A   B  C
0  11  14  7
1  12   5  8
2  13   6  9
.loc[], .iloc[], .ix[]

These can accept a callable, and a tuple of callable as a slicer. The callable can return a valid boolean indexer or anything which is valid for these indexer’s input.

# callable returns bool indexer
In [17]: df.loc[lambda x: x.A >= 2, lambda x: x.sum() > 10]
   B  C
1  5  8
2  6  9

# callable returns list of labels
In [18]: df.loc[lambda x: [1, 2], lambda x: ['A', 'B']]
   A  B
1  2  5
2  3  6
[] indexing

Finally, you can use a callable in [] indexing of Series, DataFrame and Panel. The callable must return a valid input for [] indexing depending on its class and index type.

In [19]: df[lambda x: 'A']
0    1
1    2
2    3
Name: A, dtype: int64

Using these methods / indexers, you can chain data selection operations without using temporary variable.

In [20]: bb = pd.read_csv('data/baseball.csv', index_col='id')

In [21]: (bb.groupby(['year', 'team'])
   ....:    .sum()
   ....:    .loc[lambda df: df.r > 100]
   ....: )
           stint    g    ab    r    h  X2b  X3b  hr    rbi    sb   cs   bb  \
year team                                                                    
2007 CIN       6  379   745  101  203   35    2  36  125.0  10.0  1.0  105   
     DET       5  301  1062  162  283   54    4  37  144.0  24.0  7.0   97   
     HOU       4  311   926  109  218   47    6  14   77.0  10.0  4.0   60   
     LAN      11  413  1021  153  293   61    3  36  154.0   7.0  5.0  114   
     NYN      13  622  1854  240  509  101    3  61  243.0  22.0  4.0  174   
     SFN       5  482  1305  198  337   67    6  40  171.0  26.0  7.0  235   
     TEX       2  198   729  115  200   40    4  28  115.0  21.0  4.0   73   
     TOR       4  459  1408  187  378   96    2  58  223.0   4.0  2.0  190   

              so   ibb   hbp    sh    sf  gidp  
year team                                       
2007 CIN   127.0  14.0   1.0   1.0  15.0  18.0  
     DET   176.0   3.0  10.0   4.0   8.0  28.0  
     HOU   212.0   3.0   9.0  16.0   6.0  17.0  
     LAN   141.0   8.0   9.0   3.0   8.0  29.0  
     NYN   310.0  24.0  23.0  18.0  15.0  48.0  
     SFN   188.0  51.0   8.0  16.0   6.0  41.0  
     TEX   140.0   4.0   5.0   2.0   8.0  16.0  
     TOR   265.0  16.0  12.0   4.0  16.0  38.0  

Partial string indexing on DateTimeIndex when part of a MultiIndex

Partial string indexing now matches on DateTimeIndex when part of a MultiIndex (GH10331)

In [22]: dft2 = pd.DataFrame(np.random.randn(20, 1),
   ....:                     columns=['A'],
   ....:                     index=pd.MultiIndex.from_product([pd.date_range('20130101',
   ....:                                                                     periods=10,
   ....:                                                                     freq='12H'),
   ....:                                                      ['a', 'b']]))

In [23]: dft2
2013-01-01 00:00:00 a  1.474071
                    b -0.064034
2013-01-01 12:00:00 a -1.282782
                    b  0.781836
2013-01-02 00:00:00 a -1.071357
                    b  0.441153
2013-01-02 12:00:00 a  2.353925
...                         ...
2013-01-04 00:00:00 b -0.845696
2013-01-04 12:00:00 a -1.340896
                    b  1.846883
2013-01-05 00:00:00 a -1.328865
                    b  1.682706
2013-01-05 12:00:00 a -1.717693
                    b  0.888782

[20 rows x 1 columns]

In [24]: dft2.loc['2013-01-05']
2013-01-05 00:00:00 a -1.328865
                    b  1.682706
2013-01-05 12:00:00 a -1.717693
                    b  0.888782

On other levels

In [25]: idx = pd.IndexSlice

In [26]: dft2 = dft2.swaplevel(0, 1).sort_index()

In [27]: dft2
a 2013-01-01 00:00:00  1.474071
  2013-01-01 12:00:00 -1.282782
  2013-01-02 00:00:00 -1.071357
  2013-01-02 12:00:00  2.353925
  2013-01-03 00:00:00  0.221471
  2013-01-03 12:00:00  0.758527
  2013-01-04 00:00:00 -0.964980
...                         ...
b 2013-01-02 12:00:00  0.583787
  2013-01-03 00:00:00 -0.744471
  2013-01-03 12:00:00  1.729689
  2013-01-04 00:00:00 -0.845696
  2013-01-04 12:00:00  1.846883
  2013-01-05 00:00:00  1.682706
  2013-01-05 12:00:00  0.888782

[20 rows x 1 columns]

In [28]: dft2.loc[idx[:, '2013-01-05'], :]
a 2013-01-05 00:00:00 -1.328865
  2013-01-05 12:00:00 -1.717693
b 2013-01-05 00:00:00  1.682706
  2013-01-05 12:00:00  0.888782

Assembling Datetimes

pd.to_datetime() has gained the ability to assemble datetimes from a passed in DataFrame or a dict. (GH8158).

In [29]: df = pd.DataFrame({'year': [2015, 2016],
   ....:                    'month': [2, 3],
   ....:                    'day': [4, 5],
   ....:                    'hour': [2, 3]})

In [30]: df
   day  hour  month  year
0    4     2      2  2015
1    5     3      3  2016

Assembling using the passed frame.

In [31]: pd.to_datetime(df)
0   2015-02-04 02:00:00
1   2016-03-05 03:00:00
dtype: datetime64[ns]

You can pass only the columns that you need to assemble.

In [32]: pd.to_datetime(df[['year', 'month', 'day']])
0   2015-02-04
1   2016-03-05
dtype: datetime64[ns]

Other Enhancements

  • pd.read_csv() now supports delim_whitespace=True for the Python engine (GH12958)

  • pd.read_csv() now supports opening ZIP files that contains a single CSV, via extension inference or explict compression='zip' (GH12175)

  • pd.read_csv() now supports opening files using xz compression, via extension inference or explicit compression='xz' is specified; xz compressions is also supported by DataFrame.to_csv in the same way (GH11852)

  • pd.read_msgpack() now always gives writeable ndarrays even when compression is used (GH12359).

  • pd.read_msgpack() now supports serializing and de-serializing categoricals with msgpack (GH12573)

  • .to_json() now supports NDFrames that contain categorical and sparse data (GH10778)

  • interpolate() now supports method='akima' (GH7588).

  • pd.read_excel() now accepts path objects (e.g. pathlib.Path, py.path.local) for the file path, in line with other read_* functions (GH12655)

  • Added .weekday_name property as a component to DatetimeIndex and the .dt accessor. (GH11128)

  • Index.take now handles allow_fill and fill_value consistently (GH12631)

    In [33]: idx = pd.Index([1., 2., 3., 4.], dtype='float')
    # default, allow_fill=True, fill_value=None
    In [34]: idx.take([2, -1])
    Out[34]: Float64Index([3.0, 4.0], dtype='float64')
    In [35]: idx.take([2, -1], fill_value=True)
    Out[35]: Float64Index([3.0, nan], dtype='float64')
  • Index now supports .str.get_dummies() which returns MultiIndex, see Creating Indicator Variables (GH10008, GH10103)

    In [36]: idx = pd.Index(['a|b', 'a|c', 'b|c'])
    In [37]: idx.str.get_dummies('|')
    MultiIndex(levels=[[0, 1], [0, 1], [0, 1]],
               labels=[[1, 1, 0], [1, 0, 1], [0, 1, 1]],
               names=[u'a', u'b', u'c'])
  • pd.crosstab() has gained a normalize argument for normalizing frequency tables (GH12569). Examples in the updated docs here.

  • .resample(..).interpolate() is now supported (GH12925)

  • .isin() now accepts passed sets (GH12988)

Sparse changes

These changes conform sparse handling to return the correct types and work to make a smoother experience with indexing.

SparseArray.take now returns a scalar for scalar input, SparseArray for others. Furthermore, it handles a negative indexer with the same rule as Index (GH10560, GH12796)

In [38]: s = pd.SparseArray([np.nan, np.nan, 1, 2, 3, np.nan, 4, 5, np.nan, 6])

In [39]: s.take(0)
Out[39]: nan

In [40]: s.take([1, 2, 3])
[nan, 1.0, 2.0]
Fill: nan
Indices: array([1, 2], dtype=int32)
  • Bug in SparseSeries[] indexing with Ellipsis raises KeyError (GH9467)
  • Bug in SparseArray[] indexing with tuples are not handled properly (GH12966)
  • Bug in SparseSeries.loc[] with list-like input raises TypeError (GH10560)
  • Bug in SparseSeries.iloc[] with scalar input may raise IndexError (GH10560)
  • Bug in SparseSeries.loc[], .iloc[] with slice returns SparseArray, rather than SparseSeries (GH10560)
  • Bug in SparseDataFrame.loc[], .iloc[] may results in dense Series, rather than SparseSeries (GH12787)
  • Bug in SparseArray addition ignores fill_value of right hand side (GH12910)
  • Bug in SparseArray mod raises AttributeError (GH12910)
  • Bug in SparseArray pow calculates 1 ** np.nan as np.nan which must be 1 (GH12910)
  • Bug in SparseArray comparison output may incorrect result or raise ValueError (GH12971)
  • Bug in SparseSeries.__repr__ raises TypeError when it is longer than max_rows (GH10560)
  • Bug in SparseSeries.shape ignores fill_value (GH10452)
  • Bug in SparseSeries and SparseArray may have different dtype from its dense values (GH12908)
  • Bug in SparseSeries.reindex incorrectly handle fill_value (GH12797)
  • Bug in SparseArray.to_frame() results in DataFrame, rather than SparseDataFrame (GH9850)
  • Bug in SparseSeries.value_counts() does not count fill_value (GH6749)
  • Bug in SparseArray.to_dense() does not preserve dtype (GH10648)
  • Bug in SparseArray.to_dense() incorrectly handle fill_value (GH12797)
  • Bug in pd.concat() of SparseSeries results in dense (GH10536)
  • Bug in pd.concat() of SparseDataFrame incorrectly handle fill_value (GH9765)
  • Bug in pd.concat() of SparseDataFrame may raise AttributeError (GH12174)
  • Bug in SparseArray.shift() may raise NameError or TypeError (GH12908)

API changes

.groupby(..).nth() changes

The index in .groupby(..).nth() output is now more consistent when the as_index argument is passed (GH11039):

In [41]: df = DataFrame({'A' : ['a', 'b', 'a'],
   ....:                 'B' : [1, 2, 3]})

In [42]: df
   A  B
0  a  1
1  b  2
2  a  3

Previous Behavior:

In [3]: df.groupby('A', as_index=True)['B'].nth(0)
0    1
1    2
Name: B, dtype: int64

In [4]: df.groupby('A', as_index=False)['B'].nth(0)
0    1
1    2
Name: B, dtype: int64

New Behavior:

In [43]: df.groupby('A', as_index=True)['B'].nth(0)
a    1
b    2
Name: B, dtype: int64

In [44]: df.groupby('A', as_index=False)['B'].nth(0)
0    1
1    2
Name: B, dtype: int64

Furthermore, previously, a .groupby would always sort, regardless if sort=False was passed with .nth().

In [45]: np.random.seed(1234)

In [46]: df = pd.DataFrame(np.random.randn(100, 2), columns=['a', 'b'])

In [47]: df['c'] = np.random.randint(0, 4, 100)

Previous Behavior:

In [4]: df.groupby('c', sort=True).nth(1)
          a         b
0 -0.334077  0.002118
1  0.036142 -2.074978
2 -0.720589  0.887163
3  0.859588 -0.636524

In [5]: df.groupby('c', sort=False).nth(1)
          a         b
0 -0.334077  0.002118
1  0.036142 -2.074978
2 -0.720589  0.887163
3  0.859588 -0.636524

New Behavior:

In [48]: df.groupby('c', sort=True).nth(1)
          a         b
0 -0.334077  0.002118
1  0.036142 -2.074978
2 -0.720589  0.887163
3  0.859588 -0.636524

In [49]: df.groupby('c', sort=False).nth(1)
          a         b
2 -0.720589  0.887163
3  0.859588 -0.636524
0 -0.334077  0.002118
1  0.036142 -2.074978

numpy function compatibility

Compatibility between pandas array-like methods (e.g. sum and take) and their numpy counterparts has been greatly increased by augmenting the signatures of the pandas methods so as to accept arguments that can be passed in from numpy, even if they are not necessarily used in the pandas implementation (GH12644, GH12638, GH12687)

  • .searchsorted() for Index and TimedeltaIndex now accept a sorter argument to maintain compatibility with numpy’s searchsorted function (GH12238)
  • Bug in numpy compatibility of np.round() on a Series (GH12600)

An example of this signature augmentation is illustrated below:

In [50]: sp = pd.SparseDataFrame([1, 2, 3])

In [51]: sp
0  1.0
1  2.0
2  3.0

Previous behaviour:

In [2]: np.cumsum(sp, axis=0)
TypeError: cumsum() takes at most 2 arguments (4 given)

New behaviour:

In [52]: np.cumsum(sp, axis=0)
0  1.0
1  3.0
2  6.0

Using .apply on groupby resampling

Using apply on resampling groupby operations (using a pd.TimeGrouper) now has the same output types as similar apply calls on other groupby operations. (GH11742).

In [53]: df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']),
   ....:                   'value': [10, 13]})

In [54]: df
        date  value
0 2000-10-10     10
1 2000-11-10     13

Previous behavior:

In [1]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
TypeError: cannot concatenate a non-NDFrame object

# Output is a Series
In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
2000-10-31  value    10
2000-11-30  value    13
dtype: int64

New Behavior:

# Output is a Series
In [55]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
2000-10-31    10
2000-11-30    13
Freq: M, dtype: int64

# Output is a DataFrame
In [56]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
2000-10-31     10
2000-11-30     13

Changes in read_csv exceptions

In order to standardize the read_csv API for both the c and python engines, both will now raise an EmptyDataError, a subclass of ValueError, in response to empty columns or header (GH12493, GH12506)

Previous behaviour:

In [1]: df = pd.read_csv(StringIO(''), engine='c')
ValueError: No columns to parse from file

In [2]: df = pd.read_csv(StringIO(''), engine='python')

New behaviour:

In [1]: df = pd.read_csv(StringIO(''), engine='c')
... No columns to parse from file

In [2]: df = pd.read_csv(StringIO(''), engine='python')
... No columns to parse from file

In addition to this error change, several others have been made as well:

  • CParserError now sub-classes ValueError instead of just a Exception (GH12551)
  • A CParserError is now raised instead of a generic Exception in read_csv when the c engine cannot parse a column (GH12506)
  • A ValueError is now raised instead of a generic Exception in read_csv when the c engine encounters a NaN value in an integer column (GH12506)
  • A ValueError is now raised instead of a generic Exception in read_csv when true_values is specified, and the c engine encounters an element in a column containing unencodable bytes (GH12506)
  • pandas.parser.OverflowError exception has been removed and has been replaced with Python’s built-in OverflowError exception (GH12506)
  • pd.read_csv() no longer allows a combination of strings and integers for the usecols parameter (GH12678)

to_datetime error changes

Bugs in pd.to_datetime() when passing a unit with convertible entries and errors='coerce' or non-convertible with errors='ignore'. Furthermore, an OutOfBoundsDateime exception will be raised when an out-of-range value is encountered for that unit when errors='raise'. (GH11758, GH13052, GH13059)

Previous behaviour:

In [27]: pd.to_datetime(1420043460, unit='s', errors='coerce')
Out[27]: NaT

In [28]: pd.to_datetime(11111111, unit='D', errors='ignore')
OverflowError: Python int too large to convert to C long

In [29]: pd.to_datetime(11111111, unit='D', errors='raise')
OverflowError: Python int too large to convert to C long

New behaviour:

In [2]: pd.to_datetime(1420043460, unit='s', errors='coerce')
Out[2]: Timestamp('2014-12-31 16:31:00')

In [3]: pd.to_datetime(11111111, unit='D', errors='ignore')
Out[3]: 11111111

In [4]: pd.to_datetime(11111111, unit='D', errors='raise')
OutOfBoundsDatetime: cannot convert input with unit 'D'

Other API changes

  • .swaplevel() for Series, DataFrame, Panel, and MultiIndex now features defaults for its first two parameters i and j that swap the two innermost levels of the index. (GH12934)
  • .searchsorted() for Index and TimedeltaIndex now accept a sorter argument to maintain compatibility with numpy’s searchsorted function (GH12238)
  • Period and PeriodIndex now raises IncompatibleFrequency error which inherits ValueError rather than raw ValueError (GH12615)
  • Series.apply for category dtype now applies the passed function to each of the .categories (and not the .codes), and returns a category dtype if possible (GH12473)
  • read_csv will now raise a TypeError if parse_dates is neither a boolean, list, or dictionary (matches the doc-string) (GH5636)
  • The default for .query()/.eval() is now engine=None, which will use numexpr if it’s installed; otherwise it will fallback to the python engine. This mimics the pre-0.18.1 behavior if numexpr is installed (and which, previously, if numexpr was not installed, .query()/.eval() would raise). (GH12749)
  • pd.show_versions() now includes pandas_datareader version (GH12740)
  • Provide a proper __name__ and __qualname__ attributes for generic functions (GH12021)
  • pd.concat(ignore_index=True) now uses RangeIndex as default (GH12695)
  • pd.merge() and DataFrame.join() will show a UserWarning when merging/joining a single- with a multi-leveled dataframe (GH9455, GH12219)
  • Compat with scipy > 0.17 for deprecated piecewise_polynomial interpolation method; support for the replacement from_derivatives method (GH12887)


  • The method name Index.sym_diff() is deprecated and can be replaced by Index.symmetric_difference() (GH12591)
  • The method name Categorical.sort() is deprecated in favor of Categorical.sort_values() (GH12882)

Performance Improvements

  • Improved speed of SAS reader (GH12656, GH12961)
  • Performance improvements in .groupby(..).cumcount() (GH11039)
  • Improved memory usage in pd.read_csv() when using skiprows=an_integer (GH13005)
  • Improved performance of DataFrame.to_sql when checking case sensitivity for tables. Now only checks if table has been created correctly when table name is not lower case. (GH12876)
  • Improved performance of Period construction and time series plotting (GH12903, GH11831).
  • Improved performance of .str.encode() and .str.decode() methods (GH13008)
  • Improved performance of to_numeric if input is numeric dtype (GH12777)
  • Improved performance of sparse arithmetic with IntIndex (GH13036)

Bug Fixes

  • usecols parameter in pd.read_csv is now respected even when the lines of a CSV file are not even (GH12203)
  • Bug in groupby.transform(..) when axis=1 is specified with a non-monotonic ordered index (GH12713)
  • Bug in Period and PeriodIndex creation raises KeyError if freq="Minute" is specified. Note that “Minute” freq is deprecated in v0.17.0, and recommended to use freq="T" instead (GH11854)
  • Bug in .resample(...).count() with a PeriodIndex always raising a TypeError (GH12774)
  • Bug in .resample(...) with a PeriodIndex casting to a DatetimeIndex when empty (GH12868)
  • Bug in .resample(...) with a PeriodIndex when resampling to an existing frequency (GH12770)
  • Bug in printing data which contains Period with different freq raises ValueError (GH12615)
  • Bug in Series construction with Categorical and dtype='category' is specified (GH12574)
  • Bugs in concatenation with a coercable dtype was too aggressive, resulting in different dtypes in outputformatting when an object was longer than display.max_rows (GH12411, GH12045, GH11594, GH10571, GH12211)
  • Bug in float_format option with option not being validated as a callable. (GH12706)
  • Bug in GroupBy.filter when dropna=False and no groups fulfilled the criteria (GH12768)
  • Bug in __name__ of .cum* functions (GH12021)
  • Bug in .astype() of a Float64Inde/Int64Index to an Int64Index (GH12881)
  • Bug in roundtripping an integer based index in .to_json()/.read_json() when orient='index' (the default) (GH12866)
  • Bug in plotting Categorical dtypes cause error when attempting stacked bar plot (GH13019)
  • Compat with >= numpy 1.11 for NaT comparions (GH12969)
  • Bug in .drop() with a non-unique MultiIndex. (GH12701)
  • Bug in .concat of datetime tz-aware and naive DataFrames (GH12467)
  • Bug in correctly raising a ValueError in .resample(..).fillna(..) when passing a non-string (GH12952)
  • Bug fixes in various encoding and header processing issues in pd.read_sas() (GH12659, GH12654, GH12647, GH12809)
  • Bug in pd.crosstab() where would silently ignore aggfunc if values=None (GH12569).
  • Potential segfault in DataFrame.to_json when serialising datetime.time (GH11473).
  • Potential segfault in DataFrame.to_json when attempting to serialise 0d array (GH11299).
  • Segfault in to_json when attempting to serialise a DataFrame or Series with non-ndarray values; now supports serialization of category, sparse, and datetime64[ns, tz] dtypes (GH10778).
  • Bug in DataFrame.to_json with unsupported dtype not passed to default handler (GH12554).
  • Bug in .align not returning the sub-class (GH12983)
  • Bug in aligning a Series with a DataFrame (GH13037)
  • Bug in ABCPanel in which Panel4D was not being considered as a valid instance of this generic type (GH12810)
  • Bug in consistency of .name on .groupby(..).apply(..) cases (GH12363)
  • Bug in Timestamp.__repr__ that caused pprint to fail in nested structures (GH12622)
  • Bug in Timedelta.min and Timedelta.max, the properties now report the true minimum/maximum timedeltas as recognized by pandas. See the documentation. (GH12727)
  • Bug in .quantile() with interpolation may coerce to float unexpectedly (GH12772)
  • Bug in .quantile() with empty Series may return scalar rather than empty Series (GH12772)
  • Bug in .loc with out-of-bounds in a large indexer would raise IndexError rather than KeyError (GH12527)
  • Bug in resampling when using a TimedeltaIndex and .asfreq(), would previously not include the final fencepost (GH12926)
  • Bug in equality testing with a Categorical in a DataFrame (GH12564)
  • Bug in GroupBy.first(), .last() returns incorrect row when TimeGrouper is used (GH7453)
  • Bug in pd.read_csv() with the c engine when specifying skiprows with newlines in quoted items (GH10911, GH12775)
  • Bug in DataFrame timezone lost when assigning tz-aware datetime Series with alignment (GH12981)
  • Bug in .value_counts() when normalize=True and dropna=True where nulls still contributed to the normalized count (GH12558)
  • Bug in Series.value_counts() loses name if its dtype is category (GH12835)
  • Bug in Series.value_counts() loses timezone info (GH12835)
  • Bug in Series.value_counts(normalize=True) with Categorical raises UnboundLocalError (GH12835)
  • Bug in Panel.fillna() ignoring inplace=True (GH12633)
  • Bug in pd.read_csv() when specifying names, usecols, and parse_dates simultaneously with the c engine (GH9755)
  • Bug in pd.read_csv() when specifying delim_whitespace=True and lineterminator simultaneously with the c engine (GH12912)
  • Bug in Series.rename, DataFrame.rename and DataFrame.rename_axis not treating Series as mappings to relabel (GH12623).
  • Clean in .rolling.min and .rolling.max to enhance dtype handling (GH12373)
  • Bug in groupby where complex types are coerced to float (GH12902)
  • Bug in raises TypeError if its dtype is category or tz-aware datetime (GH12473)
  • Bugs on 32bit platforms for some test comparisons (GH12972)
  • Bug in index coercion when falling back from RangeIndex construction (GH12893)
  • Better error message in window functions when invalid argument (e.g. a float window) is passed (GH12669)
  • Bug in slicing subclassed DataFrame defined to return subclassed Series may return normal Series (GH11559)
  • Bug in .str accessor methods may raise ValueError if input has name and the result is DataFrame or MultiIndex (GH12617)
  • Bug in DataFrame.last_valid_index() and DataFrame.first_valid_index() on empty frames (GH12800)
  • Bug in CategoricalIndex.get_loc returns different result from regular Index (GH12531)
  • Bug in PeriodIndex.resample where name not propagated (GH12769)
  • Bug in pd.concat raises AttributeError when input data contains tz-aware datetime and timedelta (GH12620)
  • Bug in pd.concat did not handle empty Series properly (GH11082)
  • Bug in alginment when width is specified with int (GH12979)
  • Bug in fill_value is ignored if the argument to a binary operator is a constant (GH12723)
  • Bug in pd.read_html() when using bs4 flavor and parsing table with a header and only one column (GH9178)
  • Bug in .pivot_table when margins=True and dropna=True where nulls still contributed to margin count (GH12577)
  • Bug in .pivot_table when dropna=False where table index/column names disappear (GH12133)
  • Bug in pd.crosstab() when margins=True and dropna=False which raised (GH12642)
  • Bug in when name attribute can be a hashable type (GH12610)
  • Bug in .describe() resets categorical columns information (GH11558)
  • Bug where loffset argument was not applied when calling resample().count() on a timeseries (GH12725)
  • pd.read_excel() now accepts column names associated with keyword argument names (GH12870)
  • Bug in pd.to_numeric() with Index returns np.ndarray, rather than Index (GH12777)
  • Bug in pd.to_numeric() with datetime-like may raise TypeError (GH12777)
  • Bug in pd.to_numeric() with scalar raises ValueError (GH12777)

v0.18.0 (March 13, 2016)

This is a major release from 0.17.1 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all users upgrade to this version.


pandas >= 0.18.0 no longer supports compatibility with Python version 2.6 and 3.3 (GH7718, GH11273)


numexpr version 2.4.4 will now show a warning and not be used as a computation back-end for pandas because of some buggy behavior. This does not affect other versions (>= 2.1 and >= 2.4.6). (GH12489)

Highlights include:

  • Moving and expanding window functions are now methods on Series and DataFrame, similar to .groupby, see here.
  • Adding support for a RangeIndex as a specialized form of the Int64Index for memory savings, see here.
  • API breaking change to the .resample method to make it more .groupby like, see here.
  • Removal of support for positional indexing with floats, which was deprecated since 0.14.0. This will now raise a TypeError, see here.
  • The .to_xarray() function has been added for compatibility with the xarray package, see here.
  • The read_sas function has been enhanced to read sas7bdat files, see here.
  • Addition of the .str.extractall() method, and API changes to the .str.extract() method and method.
  • pd.test() top-level nose test runner is available (GH4327).

Check the API Changes and deprecations before updating.

New features

Window functions are now methods

Window functions have been refactored to be methods on Series/DataFrame objects, rather than top-level functions, which are now deprecated. This allows these window-type functions, to have a similar API to that of .groupby. See the full documentation here (GH11603, GH12373)

In [1]: np.random.seed(1234)

In [2]: df = pd.DataFrame({'A' : range(10), 'B' : np.random.randn(10)})

In [3]: df
   A         B
0  0  0.471435
1  1 -1.190976
2  2  1.432707
3  3 -0.312652
4  4 -0.720589
5  5  0.887163
6  6  0.859588
7  7 -0.636524
8  8  0.015696
9  9 -2.242685

Previous Behavior:

In [8]: pd.rolling_mean(df,window=3)
        FutureWarning: pd.rolling_mean is deprecated for DataFrame and will be removed in a future version, replace with
    A         B
0 NaN       NaN
1 NaN       NaN
2   1  0.237722
3   2 -0.023640
4   3  0.133155
5   4 -0.048693
6   5  0.342054
7   6  0.370076
8   7  0.079587
9   8 -0.954504

New Behavior:

In [4]: r = df.rolling(window=3)

These show a descriptive repr

In [5]: r
Out[5]: Rolling [window=3,center=False,axis=0]

with tab-completion of available methods and properties.

In [9]: r.
r.A           r.agg         r.apply       r.count       r.exclusions  r.max         r.median        r.skew        r.sum
r.B           r.aggregate   r.corr        r.cov         r.kurt        r.mean        r.min         r.quantile    r.std         r.var

The methods operate on the Rolling object itself

In [6]: r.mean()
     A         B
0  NaN       NaN
1  NaN       NaN
2  1.0  0.237722
3  2.0 -0.023640
4  3.0  0.133155
5  4.0 -0.048693
6  5.0  0.342054
7  6.0  0.370076
8  7.0  0.079587
9  8.0 -0.954504

They provide getitem accessors

In [7]: r['A'].mean()
0    NaN
1    NaN
2    1.0
3    2.0
4    3.0
5    4.0
6    5.0
7    6.0
8    7.0
9    8.0
Name: A, dtype: float64

And multiple aggregations

In [8]: r.agg({'A' : ['mean','std'],
   ...:        'B' : ['mean','std']})
     A              B          
  mean  std      mean       std
0  NaN  NaN       NaN       NaN
1  NaN  NaN       NaN       NaN
2  1.0  1.0  0.237722  1.327364
3  2.0  1.0 -0.023640  1.335505
4  3.0  1.0  0.133155  1.143778
5  4.0  1.0 -0.048693  0.835747
6  5.0  1.0  0.342054  0.920379
7  6.0  1.0  0.370076  0.871850
8  7.0  1.0  0.079587  0.750099
9  8.0  1.0 -0.954504  1.162285

Changes to rename

Series.rename and NDFrame.rename_axis can now take a scalar or list-like argument for altering the Series or axis name, in addition to their old behaviors of altering labels. (GH9494, GH11965)

In [9]: s = pd.Series(np.random.randn(5))

In [10]: s.rename('newname')
0    1.150036
1    0.991946
2    0.953324
3   -2.021255
4   -0.334077
Name: newname, dtype: float64
In [11]: df = pd.DataFrame(np.random.randn(5, 2))

In [12]: (df.rename_axis("indexname")
   ....:    .rename_axis("columns_name", axis="columns"))
columns_name         0         1
0             0.002118  0.405453
1             0.289092  1.321158
2            -1.546906 -0.202646
3            -0.655969  0.193421
4             0.553439  1.318152

The new functionality works well in method chains. Previously these methods only accepted functions or dicts mapping a label to a new label. This continues to work as before for function or dict-like values.

Range Index

A RangeIndex has been added to the Int64Index sub-classes to support a memory saving alternative for common use cases. This has a similar implementation to the python range object (xrange in python 2), in that it only stores the start, stop, and step values for the index. It will transparently interact with the user API, converting to Int64Index if needed.

This will now be the default constructed index for NDFrame objects, rather than previous an Int64Index. (GH939, GH12070, GH12071, GH12109, GH12888)

Previous Behavior:

In [3]: s = pd.Series(range(1000))

In [4]: s.index
Int64Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
            990, 991, 992, 993, 994, 995, 996, 997, 998, 999], dtype='int64', length=1000)

In [6]: s.index.nbytes
Out[6]: 8000

New Behavior:

In [13]: s = pd.Series(range(1000))

In [14]: s.index
Out[14]: RangeIndex(start=0, stop=1000, step=1)

In [15]: s.index.nbytes
Out[15]: 72

Changes to str.extract

The .str.extract method takes a regular expression with capture groups, finds the first match in each subject string, and returns the contents of the capture groups (GH11386).

In v0.18.0, the expand argument was added to extract.

  • expand=False: it returns a Series, Index, or DataFrame, depending on the subject and regular expression pattern (same behavior as pre-0.18.0).
  • expand=True: it always returns a DataFrame, which is more consistent and less confusing from the perspective of a user.

Currently the default is expand=None which gives a FutureWarning and uses expand=False. To avoid this warning, please explicitly specify expand.

In [1]: pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=None)
FutureWarning: currently extract(expand=None) means expand=False (return Index/Series/DataFrame)
but in a future version of pandas this will be changed to expand=True (return DataFrame)

0      1
1      2
2    NaN
dtype: object

Extracting a regular expression with one group returns a Series if expand=False.

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

It returns a DataFrame with one column if expand=True.

In [17]: pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=True)
0    1
1    2
2  NaN

Calling on an Index with a regex with exactly one capture group returns an Index if expand=False.

In [18]: s = pd.Series(["a1", "b2", "c3"], ["A11", "B22", "C33"])

In [19]: s.index
Out[19]: Index([u'A11', u'B22', u'C33'], dtype='object')

In [20]: s.index.str.extract("(?P<letter>[a-zA-Z])", expand=False)
Out[20]: Index([u'A', u'B', u'C'], dtype='object', name=u'letter')

It returns a DataFrame with one column if expand=True.

In [21]: s.index.str.extract("(?P<letter>[a-zA-Z])", expand=True)
0      A
1      B
2      C

Calling on an Index with a regex with more than one capture group raises ValueError if expand=False.

>>> s.index.str.extract("(?P<letter>[a-zA-Z])([0-9]+)", expand=False)
ValueError: only one regex group is supported with Index

It returns a DataFrame if expand=True.

In [22]: s.index.str.extract("(?P<letter>[a-zA-Z])([0-9]+)", expand=True)
  letter   1
0      A  11
1      B  22
2      C  33

In summary, extract(expand=True) always returns a DataFrame with a row for every subject string, and a column for every capture group.

Addition of str.extractall

The .str.extractall method was added (GH11386). Unlike extract, which returns only the first match.

In [23]: s = pd.Series(["a1a2", "b1", "c1"], ["A", "B", "C"])

In [24]: s
A    a1a2
B      b1
C      c1
dtype: object

In [25]: s.str.extract("(?P<letter>[ab])(?P<digit>\d)", expand=False)
  letter digit
A      a     1
B      b     1
C    NaN   NaN

The extractall method returns all matches.

In [26]: s.str.extractall("(?P<letter>[ab])(?P<digit>\d)")
        letter digit
A 0          a     1
  1          a     2
B 0          b     1

Changes to

The method concatenates the members of a Series. Before, if NaN values were present in the Series, calling on it would return NaN, unlike the rest of the Series.str.* API. This behavior has been amended to ignore NaN values by default. (GH11435).

A new, friendlier ValueError is added to protect against the mistake of supplying the sep as an arg, rather than as a kwarg. (GH11334).

In [27]: pd.Series(['a','b',np.nan,'c'])' ')
Out[27]: 'a b c'

In [28]: pd.Series(['a','b',np.nan,'c'])' ', na_rep='?')
Out[28]: 'a b ? c'
In [2]: pd.Series(['a','b',np.nan,'c'])' ')
ValueError: Did you mean to supply a `sep` keyword?

Datetimelike rounding

DatetimeIndex, Timestamp, TimedeltaIndex, Timedelta have gained the .round(), .floor() and .ceil() method for datetimelike rounding, flooring and ceiling. (GH4314, GH11963)

Naive datetimes

In [29]: dr = pd.date_range('20130101 09:12:56.1234', periods=3)

In [30]: dr
DatetimeIndex(['2013-01-01 09:12:56.123400', '2013-01-02 09:12:56.123400',
               '2013-01-03 09:12:56.123400'],
              dtype='datetime64[ns]', freq='D')

In [31]: dr.round('s')
DatetimeIndex(['2013-01-01 09:12:56', '2013-01-02 09:12:56',
               '2013-01-03 09:12:56'],
              dtype='datetime64[ns]', freq=None)

# Timestamp scalar
In [32]: dr[0]
Out[32]: Timestamp('2013-01-01 09:12:56.123400', offset='D')

In [33]: dr[0].round('10s')
Out[33]: Timestamp('2013-01-01 09:13:00')

Tz-aware are rounded, floored and ceiled in local times

In [34]: dr = dr.tz_localize('US/Eastern')

In [35]: dr
DatetimeIndex(['2013-01-01 09:12:56.123400-05:00',
               '2013-01-02 09:12:56.123400-05:00',
               '2013-01-03 09:12:56.123400-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq='D')

In [36]: dr.round('s')
DatetimeIndex(['2013-01-01 09:12:56-05:00', '2013-01-02 09:12:56-05:00',
               '2013-01-03 09:12:56-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq=None)


In [37]: t = timedelta_range('1 days 2 hr 13 min 45 us',periods=3,freq='d')

In [38]: t
TimedeltaIndex(['1 days 02:13:00.000045', '2 days 02:13:00.000045',
                '3 days 02:13:00.000045'],
               dtype='timedelta64[ns]', freq='D')

In [39]: t.round('10min')
Out[39]: TimedeltaIndex(['1 days 02:10:00', '2 days 02:10:00', '3 days 02:10:00'], dtype='timedelta64[ns]', freq=None)

# Timedelta scalar
In [40]: t[0]
Out[40]: Timedelta('1 days 02:13:00.000045')

In [41]: t[0].round('2h')
Out[41]: Timedelta('1 days 02:00:00')

In addition, .round(), .floor() and .ceil() will be available thru the .dt accessor of Series.

In [42]: s = pd.Series(dr)

In [43]: s
0   2013-01-01 09:12:56.123400-05:00
1   2013-01-02 09:12:56.123400-05:00
2   2013-01-03 09:12:56.123400-05:00
dtype: datetime64[ns, US/Eastern]

In [44]: s.dt.round('D')
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

Formatting of Integers in FloatIndex

Integers in FloatIndex, e.g. 1., are now formatted with a decimal point and a 0 digit, e.g. 1.0 (GH11713) This change not only affects the display to the console, but also the output of IO methods like .to_csv or .to_html.

Previous Behavior:

In [2]: s = pd.Series([1,2,3], index=np.arange(3.))

In [3]: s
0    1
1    2
2    3
dtype: int64

In [4]: s.index
Out[4]: Float64Index([0.0, 1.0, 2.0], dtype='float64')

In [5]: print(s.to_csv(path=None))

New Behavior:

In [45]: s = pd.Series([1,2,3], index=np.arange(3.))

In [46]: s
0.0    1
1.0    2
2.0    3
dtype: int64

In [47]: s.index
Out[47]: Float64Index([0.0, 1.0, 2.0], dtype='float64')

In [48]: print(s.to_csv(path=None))

Changes to dtype assignment behaviors

When a DataFrame’s slice is updated with a new slice of the same dtype, the dtype of the DataFrame will now remain the same. (GH10503)

Previous Behavior:

In [5]: df = pd.DataFrame({'a': [0, 1, 1],
                           'b': pd.Series([100, 200, 300], dtype='uint32')})

In [7]: df.dtypes
a     int64
b    uint32
dtype: object

In [8]: ix = df['a'] == 1

In [9]: df.loc[ix, 'b'] = df.loc[ix, 'b']

In [11]: df.dtypes
a    int64
b    int64
dtype: object

New Behavior:

In [49]: df = pd.DataFrame({'a': [0, 1, 1],
   ....:                    'b': pd.Series([100, 200, 300], dtype='uint32')})

In [50]: df.dtypes
a     int64
b    uint32
dtype: object

In [51]: ix = df['a'] == 1

In [52]: df.loc[ix, 'b'] = df.loc[ix, 'b']

In [53]: df.dtypes
a     int64
b    uint32
dtype: object

When a DataFrame’s integer slice is partially updated with a new slice of floats that could potentially be downcasted to integer without losing precision, the dtype of the slice will be set to float instead of integer.

Previous Behavior:

In [4]: df = pd.DataFrame(np.array(range(1,10)).reshape(3,3),
                          index=[[4,4,8], [8,10,12]])

In [5]: df
      a  b  c
4 8   1  2  3
  10  4  5  6
8 12  7  8  9

In [7]: df.ix[4, 'c'] = np.array([0., 1.])

In [8]: df
      a  b  c
4 8   1  2  0
  10  4  5  1
8 12  7  8  9

New Behavior:

In [54]: df = pd.DataFrame(np.array(range(1,10)).reshape(3,3),
   ....:                   columns=list('abc'),
   ....:                   index=[[4,4,8], [8,10,12]])

In [55]: df
      a  b  c
4 8   1  2  3
  10  4  5  6
8 12  7  8  9

In [56]: df.ix[4, 'c'] = np.array([0., 1.])

In [57]: df
      a  b    c
4 8   1  2  0.0
  10  4  5  1.0
8 12  7  8  9.0


In a future version of pandas, we will be deprecating Panel and other > 2 ndim objects. In order to provide for continuity, all NDFrame objects have gained the .to_xarray() method in order to convert to xarray objects, which has a pandas-like interface for > 2 ndim. (GH11972)

See the xarray full-documentation here.

In [1]: p = Panel(np.arange(2*3*4).reshape(2,3,4))

In [2]: p.to_xarray()
<xarray.DataArray (items: 2, major_axis: 3, minor_axis: 4)>
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])
  * items       (items) int64 0 1
  * major_axis  (major_axis) int64 0 1 2
  * minor_axis  (minor_axis) int64 0 1 2 3

Latex Representation

DataFrame has gained a ._repr_latex_() method in order to allow for conversion to latex in a ipython/jupyter notebook using nbconvert. (GH11778)

Note that this must be activated by setting the option pd.display.latex.repr=True (GH12182)

For example, if you have a jupyter notebook you plan to convert to latex using nbconvert, place the statement pd.display.latex.repr=True in the first cell to have the contained DataFrame output also stored as latex.

The options display.latex.escape and display.latex.longtable have also been added to the configuration and are used automatically by the to_latex method. See the available options docs for more info.

pd.read_sas() changes

read_sas has gained the ability to read SAS7BDAT files, including compressed files. The files can be read in entirety, or incrementally. For full details see here. (GH4052)

Other enhancements

  • Handle truncated floats in SAS xport files (GH11713)
  • Added option to hide index in Series.to_string (GH11729)
  • read_excel now supports s3 urls of the format s3://bucketname/filename (GH11447)
  • add support for AWS_S3_HOST env variable when reading from s3 (GH12198)
  • A simple version of Panel.round() is now implemented (GH11763)
  • For Python 3.x, round(DataFrame), round(Series), round(Panel) will work (GH11763)
  • sys.getsizeof(obj) returns the memory usage of a pandas object, including the values it contains (GH11597)
  • Series gained an is_unique attribute (GH11946)
  • DataFrame.quantile and Series.quantile now accept interpolation keyword (GH10174).
  • Added for more flexible formatting of cell values (GH11692)
  • DataFrame.select_dtypes now allows the np.float16 typecode (GH11990)
  • pivot_table() now accepts most iterables for the values parameter (GH12017)
  • Added Google BigQuery service account authentication support, which enables authentication on remote servers. (GH11881, GH12572). For further details see here
  • HDFStore is now iterable: for k in store is equivalent to for k in store.keys() (GH12221).
  • Add missing methods/fields to .dt for Period (GH8848)
  • The entire codebase has been PEP-ified (GH12096)

Backwards incompatible API changes

  • the leading whitespaces have been removed from the output of .to_string(index=False) method (GH11833)
  • the out parameter has been removed from the Series.round() method. (GH11763)
  • DataFrame.round() leaves non-numeric columns unchanged in its return, rather than raises. (GH11885)
  • DataFrame.head(0) and DataFrame.tail(0) return empty frames, rather than self. (GH11937)
  • Series.head(0) and Series.tail(0) return empty series, rather than self. (GH11937)
  • to_msgpack and read_msgpack encoding now defaults to 'utf-8'. (GH12170)
  • the order of keyword arguments to text file parsing functions (.read_csv(), .read_table(), .read_fwf()) changed to group related arguments. (GH11555)
  • NaTType.isoformat now returns the string 'NaT to allow the result to be passed to the constructor of Timestamp. (GH12300)

NaT and Timedelta operations

NaT and Timedelta have expanded arithmetic operations, which are extended to Series arithmetic where applicable. Operations defined for datetime64[ns] or timedelta64[ns] are now also defined for NaT (GH11564).

NaT now supports arithmetic operations with integers and floats.

In [58]: pd.NaT * 1
Out[58]: NaT

In [59]: pd.NaT * 1.5
Out[59]: NaT

In [60]: pd.NaT / 2
Out[60]: NaT

In [61]: pd.NaT * np.nan
Out[61]: NaT

NaT defines more arithmetic operations with datetime64[ns] and timedelta64[ns].

In [62]: pd.NaT / pd.NaT
Out[62]: nan

In [63]: pd.Timedelta('1s') / pd.NaT
Out[63]: nan

NaT may represent either a datetime64[ns] null or a timedelta64[ns] null. Given the ambiguity, it is treated as a timedelta64[ns], which allows more operations to succeed.

In [64]: pd.NaT + pd.NaT
Out[64]: NaT

# same as
In [65]: pd.Timedelta('1s') + pd.Timedelta('1s')
Out[65]: Timedelta('0 days 00:00:02')

as opposed to

In [3]: pd.Timestamp('19900315') + pd.Timestamp('19900315')
TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp'

However, when wrapped in a Series whose dtype is datetime64[ns] or timedelta64[ns], the dtype information is respected.

In [1]: pd.Series([pd.NaT], dtype='<M8[ns]') + pd.Series([pd.NaT], dtype='<M8[ns]')
TypeError: can only operate on a datetimes for subtraction,
           but the operator [__add__] was passed
In [66]: pd.Series([pd.NaT], dtype='<m8[ns]') + pd.Series([pd.NaT], dtype='<m8[ns]')
0   NaT
dtype: timedelta64[ns]

Timedelta division by floats now works.

In [67]: pd.Timedelta('1s') / 2.0
Out[67]: Timedelta('0 days 00:00:00.500000')

Subtraction by Timedelta in a Series by a Timestamp works (GH11925)

In [68]: ser = pd.Series(pd.timedelta_range('1 day', periods=3))

In [69]: ser
0   1 days
1   2 days
2   3 days
dtype: timedelta64[ns]

In [70]: pd.Timestamp('2012-01-01') - ser
0   2011-12-31
1   2011-12-30
2   2011-12-29
dtype: datetime64[ns]

NaT.isoformat() now returns 'NaT'. This change allows allows pd.Timestamp to rehydrate any timestamp like object from its isoformat (GH12300).

Changes to msgpack

Forward incompatible changes in msgpack writing format were made over 0.17.0 and 0.18.0; older versions of pandas cannot read files packed by newer versions (GH12129, GH10527)

Bugs in to_msgpack and read_msgpack introduced in 0.17.0 and fixed in 0.18.0, caused files packed in Python 2 unreadable by Python 3 (GH12142). The following table describes the backward and forward compat of msgpacks.


Packed with Can be unpacked with
pre-0.17 / Python 2 any
pre-0.17 / Python 3 any
0.17 / Python 2
  • ==0.17 / Python 2
  • >=0.18 / any Python
0.17 / Python 3 >=0.18 / any Python
0.18 >= 0.18

0.18.0 is backward-compatible for reading files packed by older versions, except for files packed with 0.17 in Python 2, in which case only they can only be unpacked in Python 2.

Signature change for .rank

Series.rank and DataFrame.rank now have the same signature (GH11759)

Previous signature

In [3]: pd.Series([0,1]).rank(method='average', na_option='keep',
                              ascending=True, pct=False)
0    1
1    2
dtype: float64

In [4]: pd.DataFrame([0,1]).rank(axis=0, numeric_only=None,
                                 method='average', na_option='keep',
                                 ascending=True, pct=False)
0  1
1  2

New signature

In [71]: pd.Series([0,1]).rank(axis=0, method='average', numeric_only=None,
   ....:                       na_option='keep', ascending=True, pct=False)
0    1.0
1    2.0
dtype: float64

In [72]: pd.DataFrame([0,1]).rank(axis=0, method='average', numeric_only=None,
   ....:                          na_option='keep', ascending=True, pct=False)
0  1.0
1  2.0

Bug in QuarterBegin with n=0

In previous versions, the behavior of the QuarterBegin offset was inconsistent depending on the date when the n parameter was 0. (GH11406)

The general semantics of anchored offsets for n=0 is to not move the date when it is an anchor point (e.g., a quarter start date), and otherwise roll forward to the next anchor point.

In [73]: d = pd.Timestamp('2014-02-01')

In [74]: d
Out[74]: Timestamp('2014-02-01 00:00:00')

In [75]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[75]: Timestamp('2014-02-01 00:00:00')

In [76]: d + pd.offsets.QuarterBegin(n=0, startingMonth=1)
Out[76]: Timestamp('2014-04-01 00:00:00')

For the QuarterBegin offset in previous versions, the date would be rolled backwards if date was in the same month as the quarter start date.

In [3]: d = pd.Timestamp('2014-02-15')

In [4]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[4]: Timestamp('2014-02-01 00:00:00')

This behavior has been corrected in version 0.18.0, which is consistent with other anchored offsets like MonthBegin and YearBegin.

In [77]: d = pd.Timestamp('2014-02-15')

In [78]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[78]: Timestamp('2014-05-01 00:00:00')

Resample API

Like the change in the window functions API above, .resample(...) is changing to have a more groupby-like API. (GH11732, GH12702, GH12202, GH12332, GH12334, GH12348, GH12448).

In [79]: np.random.seed(1234)

In [80]: df = pd.DataFrame(np.random.rand(10,4),
   ....:                   columns=list('ABCD'),
   ....:                   index=pd.date_range('2010-01-01 09:00:00', periods=10, freq='s'))

In [81]: df
                            A         B         C         D
2010-01-01 09:00:00  0.191519  0.622109  0.437728  0.785359
2010-01-01 09:00:01  0.779976  0.272593  0.276464  0.801872
2010-01-01 09:00:02  0.958139  0.875933  0.357817  0.500995
2010-01-01 09:00:03  0.683463  0.712702  0.370251  0.561196
2010-01-01 09:00:04  0.503083  0.013768  0.772827  0.882641
2010-01-01 09:00:05  0.364886  0.615396  0.075381  0.368824
2010-01-01 09:00:06  0.933140  0.651378  0.397203  0.788730
2010-01-01 09:00:07  0.316836  0.568099  0.869127  0.436173
2010-01-01 09:00:08  0.802148  0.143767  0.704261  0.704581
2010-01-01 09:00:09  0.218792  0.924868  0.442141  0.909316

Previous API:

You would write a resampling operation that immediately evaluates. If a how parameter was not provided, it would default to how='mean'.

In [6]: df.resample('2s')
                         A         B         C         D
2010-01-01 09:00:00  0.485748  0.447351  0.357096  0.793615
2010-01-01 09:00:02  0.820801  0.794317  0.364034  0.531096
2010-01-01 09:00:04  0.433985  0.314582  0.424104  0.625733
2010-01-01 09:00:06  0.624988  0.609738  0.633165  0.612452
2010-01-01 09:00:08  0.510470  0.534317  0.573201  0.806949

You could also specify a how directly

In [7]: df.resample('2s', how='sum')
                         A         B         C         D
2010-01-01 09:00:00  0.971495  0.894701  0.714192  1.587231
2010-01-01 09:00:02  1.641602  1.588635  0.728068  1.062191
2010-01-01 09:00:04  0.867969  0.629165  0.848208  1.251465
2010-01-01 09:00:06  1.249976  1.219477  1.266330  1.224904
2010-01-01 09:00:08  1.020940  1.068634  1.146402  1.613897

New API:

Now, you can write .resample(..) as a 2-stage operation like .groupby(...), which yields a Resampler.

In [82]: r = df.resample('2s')

In [83]: r
Out[83]: DatetimeIndexResampler [freq=<2 * Seconds>, axis=0, closed=left, label=left, convention=start, base=0]

You can then use this object to perform operations. These are downsampling operations (going from a higher frequency to a lower one).

In [84]: r.mean()
                            A         B         C         D
2010-01-01 09:00:00  0.485748  0.447351  0.357096  0.793615
2010-01-01 09:00:02  0.820801  0.794317  0.364034  0.531096
2010-01-01 09:00:04  0.433985  0.314582  0.424104  0.625733
2010-01-01 09:00:06  0.624988  0.609738  0.633165  0.612452
2010-01-01 09:00:08  0.510470  0.534317  0.573201  0.806949
In [85]: r.sum()
                            A         B         C         D
2010-01-01 09:00:00  0.971495  0.894701  0.714192  1.587231
2010-01-01 09:00:02  1.641602  1.588635  0.728068  1.062191
2010-01-01 09:00:04  0.867969  0.629165  0.848208  1.251465
2010-01-01 09:00:06  1.249976  1.219477  1.266330  1.224904
2010-01-01 09:00:08  1.020940  1.068634  1.146402  1.613897

Furthermore, resample now supports getitem operations to perform the resample on specific columns.

In [86]: r[['A','C']].mean()
                            A         C
2010-01-01 09:00:00  0.485748  0.357096
2010-01-01 09:00:02  0.820801  0.364034
2010-01-01 09:00:04  0.433985  0.424104
2010-01-01 09:00:06  0.624988  0.633165
2010-01-01 09:00:08  0.510470  0.573201

and .aggregate type operations.

In [87]: r.agg({'A' : 'mean', 'B' : 'sum'})
                            A         B
2010-01-01 09:00:00  0.485748  0.894701
2010-01-01 09:00:02  0.820801  1.588635
2010-01-01 09:00:04  0.433985  0.629165
2010-01-01 09:00:06  0.624988  1.219477
2010-01-01 09:00:08  0.510470  1.068634

These accessors can of course, be combined

In [88]: r[['A','B']].agg(['mean','sum'])
                            A                   B          
                         mean       sum      mean       sum
2010-01-01 09:00:00  0.485748  0.971495  0.447351  0.894701
2010-01-01 09:00:02  0.820801  1.641602  0.794317  1.588635
2010-01-01 09:00:04  0.433985  0.867969  0.314582  0.629165
2010-01-01 09:00:06  0.624988  1.249976  0.609738  1.219477
2010-01-01 09:00:08  0.510470  1.020940  0.534317  1.068634

Upsampling operations take you from a lower frequency to a higher frequency. These are now performed with the Resampler objects with backfill(), ffill(), fillna() and asfreq() methods.

In [89]: s = pd.Series(np.arange(5,dtype='int64'),
   ....:               index=date_range('2010-01-01', periods=5, freq='Q'))

In [90]: s
2010-03-31    0
2010-06-30    1
2010-09-30    2
2010-12-31    3
2011-03-31    4
Freq: Q-DEC, dtype: int64


In [6]: s.resample('M', fill_method='ffill')
2010-03-31    0
2010-04-30    0
2010-05-31    0
2010-06-30    1
2010-07-31    1
2010-08-31    1
2010-09-30    2
2010-10-31    2
2010-11-30    2
2010-12-31    3
2011-01-31    3
2011-02-28    3
2011-03-31    4
Freq: M, dtype: int64


In [91]: s.resample('M').ffill()
2010-03-31    0
2010-04-30    0
2010-05-31    0
2010-06-30    1
2010-07-31    1
2010-08-31    1
2010-09-30    2
2010-10-31    2
2010-11-30    2
2010-12-31    3
2011-01-31    3
2011-02-28    3
2011-03-31    4
Freq: M, dtype: int64


In the new API, you can either downsample OR upsample. The prior implementation would allow you to pass an aggregator function (like mean) even though you were upsampling, providing a bit of confusion.


This new API for resample includes some internal changes for the prior-to-0.18.0 API, to work with a deprecation warning in most cases, as the resample operation returns a deferred object. We can intercept operations and just do what the (pre 0.18.0) API did (with a warning). Here is a typical use case:

In [4]: r = df.resample('2s')

In [6]: r*10
pandas/tseries/ FutureWarning: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)

                      A         B         C         D
2010-01-01 09:00:00  4.857476  4.473507  3.570960  7.936154
2010-01-01 09:00:02  8.208011  7.943173  3.640340  5.310957
2010-01-01 09:00:04  4.339846  3.145823  4.241039  6.257326
2010-01-01 09:00:06  6.249881  6.097384  6.331650  6.124518
2010-01-01 09:00:08  5.104699  5.343172  5.732009  8.069486

However, getting and assignment operations directly on a Resampler will raise a ValueError:

In [7]: r.iloc[0] = 5
ValueError: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)

There is a situation where the new API can not perform all the operations when using original code. This code is intending to resample every 2s, take the mean AND then take the min of those results.

In [4]: df.resample('2s').min()
A    0.433985
B    0.314582
C    0.357096
D    0.531096
dtype: float64

The new API will:

In [92]: df.resample('2s').min()
                            A         B         C         D
2010-01-01 09:00:00  0.191519  0.272593  0.276464  0.785359
2010-01-01 09:00:02  0.683463  0.712702  0.357817  0.500995
2010-01-01 09:00:04  0.364886  0.013768  0.075381  0.368824
2010-01-01 09:00:06  0.316836  0.568099  0.397203  0.436173
2010-01-01 09:00:08  0.218792  0.143767  0.442141  0.704581

The good news is the return dimensions will differ between the new API and the old API, so this should loudly raise an exception.

To replicate the original operation

In [93]: df.resample('2s').mean().min()
A    0.433985
B    0.314582
C    0.357096
D    0.531096
dtype: float64

Changes to eval

In prior versions, new columns assignments in an eval expression resulted in an inplace change to the DataFrame. (GH9297)

In [94]: df = pd.DataFrame({'a': np.linspace(0, 10, 5), 'b': range(5)})

In [95]: df
      a  b
0   0.0  0
1   2.5  1
2   5.0  2
3   7.5  3
4  10.0  4
In [12]: df.eval('c = a + b')
FutureWarning: eval expressions containing an assignment currentlydefault to operating inplace.
This will change in a future version of pandas, use inplace=True to avoid this warning.

In [13]: df
      a  b     c
0   0.0  0   0.0
1   2.5  1   3.5
2   5.0  2   7.0
3   7.5  3  10.5
4  10.0  4  14.0

In version 0.18.0, a new inplace keyword was added to choose whether the assignment should be done inplace or return a copy.

In [96]: df
      a  b     c
0   0.0  0   0.0
1   2.5  1   3.5
2   5.0  2   7.0
3   7.5  3  10.5
4  10.0  4  14.0

In [97]: df.eval('d = c - b', inplace=False)
      a  b     c     d
0   0.0  0   0.0   0.0
1   2.5  1   3.5   2.5
2   5.0  2   7.0   5.0
3   7.5  3  10.5   7.5
4  10.0  4  14.0  10.0

In [98]: df
      a  b     c
0   0.0  0   0.0
1   2.5  1   3.5
2   5.0  2   7.0
3   7.5  3  10.5
4  10.0  4  14.0

In [99]: df.eval('d = c - b', inplace=True)

In [100]: df
      a  b     c     d
0   0.0  0   0.0   0.0
1   2.5  1   3.5   2.5
2   5.0  2   7.0   5.0
3   7.5  3  10.5   7.5
4  10.0  4  14.0  10.0


For backwards compatability, inplace defaults to True if not specified. This will change in a future version of pandas. If your code depends on an inplace assignment you should update to explicitly set inplace=True

The inplace keyword parameter was also added the query method.

In [101]: df.query('a > 5')
      a  b     c     d
3   7.5  3  10.5   7.5
4  10.0  4  14.0  10.0

In [102]: df.query('a > 5', inplace=True)

In [103]: df
      a  b     c     d
3   7.5  3  10.5   7.5
4  10.0  4  14.0  10.0


Note that the default value for inplace in a query is False, which is consistent with prior versions.

eval has also been updated to allow multi-line expressions for multiple assignments. These expressions will be evaluated one at a time in order. Only assignments are valid for multi-line expressions.

In [104]: df
      a  b     c     d
3   7.5  3  10.5   7.5
4  10.0  4  14.0  10.0

In [105]: df.eval("""
   .....: e = d + a
   .....: f = e - 22
   .....: g = f / 2.0""", inplace=True)

In [106]: df
      a  b     c     d     e    f    g
3   7.5  3  10.5   7.5  15.0 -7.0 -3.5
4  10.0  4  14.0  10.0  20.0 -2.0 -1.0

Other API Changes

  • DataFrame.between_time and Series.between_time now only parse a fixed set of time strings. Parsing of date strings is no longer supported and raises a ValueError. (GH11818)

    In [107]: s = pd.Series(range(10), pd.date_range('2015-01-01', freq='H', periods=10))
    In [108]: s.between_time("7:00am", "9:00am")
    2015-01-01 07:00:00    7
    2015-01-01 08:00:00    8
    2015-01-01 09:00:00    9
    Freq: H, dtype: int64

    This will now raise.

    In [2]: s.between_time('20150101 07:00:00','20150101 09:00:00')
    ValueError: Cannot convert arg ['20150101 07:00:00'] to a time.
  • .memory_usage() now includes values in the index, as does memory_usage in .info() (GH11597)

  • DataFrame.to_latex() now supports non-ascii encodings (eg utf-8) in Python 2 with the parameter encoding (GH7061)

  • pandas.merge() and DataFrame.merge() will show a specific error message when trying to merge with an object that is not of type DataFrame or a subclass (GH12081)

  • DataFrame.unstack and Series.unstack now take fill_value keyword to allow direct replacement of missing values when an unstack results in missing values in the resulting DataFrame. As an added benefit, specifying fill_value will preserve the data type of the original stacked data. (GH9746)

  • As part of the new API for window functions and resampling, aggregation functions have been clarified, raising more informative error messages on invalid aggregations. (GH9052). A full set of examples are presented in groupby.

  • Statistical functions for NDFrame objects (like sum(), mean(), min()) will now raise if non-numpy-compatible arguments are passed in for **kwargs (GH12301)

  • .to_latex and .to_html gain a decimal parameter like .to_csv; the default is '.' (GH12031)

  • More helpful error message when constructing a DataFrame with empty data but with indices (GH8020)

  • .describe() will now properly handle bool dtype as a categorical (GH6625)

  • More helpful error message with an invalid .transform with user defined input (GH10165)

  • Exponentially weighted functions now allow specifying alpha directly (GH10789) and raise ValueError if parameters violate 0 < alpha <= 1 (GH12492)


  • The functions pd.rolling_*, pd.expanding_*, and pd.ewm* are deprecated and replaced by the corresponding method call. Note that the new suggested syntax includes all of the arguments (even if default) (GH11603)

    In [1]: s = pd.Series(range(3))
    In [2]: pd.rolling_mean(s,window=2,min_periods=1)
            FutureWarning: pd.rolling_mean is deprecated for Series and
                 will be removed in a future version, replace with
            0    0.0
            1    0.5
            2    1.5
            dtype: float64
    In [3]: pd.rolling_cov(s, s, window=2)
            FutureWarning: pd.rolling_cov is deprecated for Series and
                 will be removed in a future version, replace with
            0    NaN
            1    0.5
            2    0.5
            dtype: float64
  • The the freq and how arguments to the .rolling, .expanding, and .ewm (new) functions are deprecated, and will be removed in a future version. You can simply resample the input prior to creating a window function. (GH11603).

    For example, instead of s.rolling(window=5,freq='D').max() to get the max value on a rolling 5 Day window, one could use s.resample('D').mean().rolling(window=5).max(), which first resamples the data to daily data, then provides a rolling 5 day window.

  • pd.tseries.frequencies.get_offset_name function is deprecated. Use offset’s .freqstr property as alternative (GH11192)

  • pandas.stats.fama_macbeth routines are deprecated and will be removed in a future version (GH6077)

  • pandas.stats.ols, pandas.stats.plm and pandas.stats.var routines are deprecated and will be removed in a future version (GH6077)

  • show a FutureWarning rather than a DeprecationWarning on using long-time deprecated syntax in, where the where clause is not a string-like (GH12027)

  • The pandas.options.display.mpl_style configuration has been deprecated and will be removed in a future version of pandas. This functionality is better handled by matplotlib’s style sheets (GH11783).

Removal of deprecated float indexers

In GH4892 indexing with floating point numbers on a non-Float64Index was deprecated (in version 0.14.0). In 0.18.0, this deprecation warning is removed and these will now raise a TypeError. (GH12165, GH12333)

In [109]: s = pd.Series([1, 2, 3], index=[4, 5, 6])

In [110]: s
4    1
5    2
6    3
dtype: int64

In [111]: s2 = pd.Series([1, 2, 3], index=list('abc'))

In [112]: s2
a    1
b    2
c    3
dtype: int64

Previous Behavior:

# this is label indexing
In [2]: s[5.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[2]: 2

# this is positional indexing
In [3]: s.iloc[1.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[3]: 2

# this is label indexing
In [4]: s.loc[5.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[4]: 2

# .ix would coerce 1.0 to the positional 1, and index
In [5]: s2.ix[1.0] = 10
FutureWarning: scalar indexers for index type Index should be integers and not floating point

In [6]: s2
a     1
b    10
c     3
dtype: int64

New Behavior:

For iloc, getting & setting via a float scalar will always raise.

In [3]: s.iloc[2.0]
TypeError: cannot do label indexing on <class 'pandas.indexes.numeric.Int64Index'> with these indexers [2.0] of <type 'float'>

Other indexers will coerce to a like integer for both getting and setting. The FutureWarning has been dropped for .loc, .ix and [].

In [113]: s[5.0]
Out[113]: 2

In [114]: s.loc[5.0]
Out[114]: 2

In [115]: s.ix[5.0]
Out[115]: 2

and setting

In [116]: s_copy = s.copy()

In [117]: s_copy[5.0] = 10

In [118]: s_copy
4     1
5    10
6     3
dtype: int64

In [119]: s_copy = s.copy()

In [120]: s_copy.loc[5.0] = 10

In [121]: s_copy
4     1
5    10
6     3
dtype: int64

In [122]: s_copy = s.copy()

In [123]: s_copy.ix[5.0] = 10

In [124]: s_copy
4     1
5    10
6     3
dtype: int64

Positional setting with .ix and a float indexer will ADD this value to the index, rather than previously setting the value by position.

In [125]: s2.ix[1.0] = 10

In [126]: s2
a       1
b       2
c       3
1.0    10
dtype: int64

Slicing will also coerce integer-like floats to integers for a non-Float64Index.

In [127]: s.loc[5.0:6]
5    2
6    3
dtype: int64

In [128]: s.ix[5.0:6]
5    2
6    3
dtype: int64

Note that for floats that are NOT coercible to ints, the label based bounds will be excluded

In [129]: s.loc[5.1:6]
6    3
dtype: int64

In [130]: s.ix[5.1:6]
6    3
dtype: int64

Float indexing on a Float64Index is unchanged.

In [131]: s = pd.Series([1, 2, 3], index=np.arange(3.))

In [132]: s[1.0]
Out[132]: 2

In [133]: s[1.0:2.5]
1.0    2
2.0    3
dtype: int64

Removal of prior version deprecations/changes

  • Removal of rolling_corr_pairwise in favor of .rolling().corr(pairwise=True) (GH4950)
  • Removal of expanding_corr_pairwise in favor of .expanding().corr(pairwise=True) (GH4950)
  • Removal of DataMatrix module. This was not imported into the pandas namespace in any event (GH12111)
  • Removal of cols keyword in favor of subset in DataFrame.duplicated() and DataFrame.drop_duplicates() (GH6680)
  • Removal of the read_frame and frame_query (both aliases for pd.read_sql) and write_frame (alias of to_sql) functions in the namespace, deprecated since 0.14.0 (GH6292).
  • Removal of the order keyword from .factorize() (GH6930)

Performance Improvements

  • Improved performance of andrews_curves (GH11534)
  • Improved huge DatetimeIndex, PeriodIndex and TimedeltaIndex‘s ops performance including NaT (GH10277)
  • Improved performance of pandas.concat (GH11958)
  • Improved performance of StataReader (GH11591)
  • Improved performance in construction of Categoricals with Series of datetimes containing NaT (GH12077)
  • Improved performance of ISO 8601 date parsing for dates without separators (GH11899), leading zeros (GH11871) and with whitespace preceding the time zone (GH9714)

Bug Fixes

  • Bug in GroupBy.size when data-frame is empty. (GH11699)
  • Bug in Period.end_time when a multiple of time period is requested (GH11738)
  • Regression in .clip with tz-aware datetimes (GH11838)
  • Bug in date_range when the boundaries fell on the frequency (GH11804, GH12409)
  • Bug in consistency of passing nested dicts to .groupby(...).agg(...) (GH9052)
  • Accept unicode in Timedelta constructor (GH11995)
  • Bug in value label reading for StataReader when reading incrementally (GH12014)
  • Bug in vectorized DateOffset when n parameter is 0 (GH11370)
  • Compat for numpy 1.11 w.r.t. NaT comparison changes (GH12049)
  • Bug in read_csv when reading from a StringIO in threads (GH11790)
  • Bug in not treating NaT as a missing value in datetimelikes when factorizing & with Categoricals (GH12077)
  • Bug in getitem when the values of a Series were tz-aware (GH12089)
  • Bug in Series.str.get_dummies when one of the variables was ‘name’ (GH12180)
  • Bug in pd.concat while concatenating tz-aware NaT series. (GH11693, GH11755, GH12217)
  • Bug in pd.read_stata with version <= 108 files (GH12232)
  • Bug in Series.resample using a frequency of Nano when the index is a DatetimeIndex and contains non-zero nanosecond parts (GH12037)
  • Bug in resampling with .nunique and a sparse index (GH12352)
  • Removed some compiler warnings (GH12471)
  • Work around compat issues with boto in python 3.5 (GH11915)
  • Bug in NaT subtraction from Timestamp or DatetimeIndex with timezones (GH11718)
  • Bug in subtraction of Series of a single tz-aware Timestamp (GH12290)
  • Use compat iterators in PY2 to support .next() (GH12299)
  • Bug in Timedelta.round with negative values (GH11690)
  • Bug in .loc against CategoricalIndex may result in normal Index (GH11586)
  • Bug in when duplicated column names exist (GH11761)
  • Bug in .copy of datetime tz-aware objects (GH11794)
  • Bug in Series.apply and where timedelta64 was not boxed (GH11349)
  • Bug in DataFrame.set_index() with tz-aware Series (GH12358)
  • Bug in subclasses of DataFrame where AttributeError did not propagate (GH11808)
  • Bug groupby on tz-aware data where selection not returning Timestamp (GH11616)
  • Bug in pd.read_clipboard and pd.to_clipboard functions not supporting Unicode; upgrade included pyperclip to v1.5.15 (GH9263)
  • Bug in DataFrame.query containing an assignment (GH8664)
  • Bug in from_msgpack where __contains__() fails for columns of the unpacked DataFrame, if the DataFrame has object columns. (GH11880)
  • Bug in .resample on categorical data with TimedeltaIndex (GH12169)
  • Bug in timezone info lost when broadcasting scalar datetime to DataFrame (GH11682)
  • Bug in Index creation from Timestamp with mixed tz coerces to UTC (GH11488)
  • Bug in to_numeric where it does not raise if input is more than one dimension (GH11776)
  • Bug in parsing timezone offset strings with non-zero minutes (GH11708)
  • Bug in df.plot using incorrect colors for bar plots under matplotlib 1.5+ (GH11614)
  • Bug in the groupby plot method when using keyword arguments (GH11805).
  • Bug in DataFrame.duplicated and drop_duplicates causing spurious matches when setting keep=False (GH11864)
  • Bug in .loc result with duplicated key may have Index with incorrect dtype (GH11497)
  • Bug in pd.rolling_median where memory allocation failed even with sufficient memory (GH11696)
  • Bug in with spurious zeros (GH12134)
  • Bug in with integer columns not starting at 0 (GH12125)
  • Bug in may not rendered properly using specific browser (GH11678)
  • Bug in rich comparison of Timedelta with a numpy.array of Timedelta that caused an infinite recursion (GH11835)
  • Bug in DataFrame.round dropping column index name (GH11986)
  • Bug in df.replace while replacing value in mixed dtype Dataframe (GH11698)
  • Bug in Index prevents copying name of passed Index, when a new name is not provided (GH11193)
  • Bug in read_excel failing to read any non-empty sheets when empty sheets exist and sheetname=None (GH11711)
  • Bug in read_excel failing to raise NotImplemented error when keywords parse_dates and date_parser are provided (GH11544)
  • Bug in read_sql with pymysql connections failing to return chunked data (GH11522)
  • Bug in .to_csv ignoring formatting parameters decimal, na_rep, float_format for float indexes (GH11553)
  • Bug in Int64Index and Float64Index preventing the use of the modulo operator (GH9244)
  • Bug in MultiIndex.drop for not lexsorted multi-indexes (GH12078)
  • Bug in DataFrame when masking an empty DataFrame (GH11859)
  • Bug in .plot potentially modifying the colors input when the number of columns didn’t match the number of series provided (GH12039).
  • Bug in Series.plot failing when index has a CustomBusinessDay frequency (GH7222).
  • Bug in .to_sql for datetime.time values with sqlite fallback (GH8341)
  • Bug in read_excel failing to read data with one column when squeeze=True (GH12157)
  • Bug in read_excel failing to read one empty column (GH12292, GH9002)
  • Bug in .groupby where a KeyError was not raised for a wrong column if there was only one row in the dataframe (GH11741)
  • Bug in .read_csv with dtype specified on empty data producing an error (GH12048)
  • Bug in .read_csv where strings like '2E' are treated as valid floats (GH12237)
  • Bug in building pandas with debugging symbols (GH12123)
  • Removed millisecond property of DatetimeIndex. This would always raise a ValueError (GH12019).
  • Bug in Series constructor with read-only data (GH11502)
  • Removed pandas.util.testing.choice(). Should use np.random.choice(), instead. (GH12386)
  • Bug in .loc setitem indexer preventing the use of a TZ-aware DatetimeIndex (GH12050)
  • Bug in .style indexes and multi-indexes not appearing (GH11655)
  • Bug in to_msgpack and from_msgpack which did not correctly serialize or deserialize NaT (GH12307).
  • Bug in .skew and .kurt due to roundoff error for highly similar values (GH11974)
  • Bug in Timestamp constructor where microsecond resolution was lost if HHMMSS were not separated with ‘:’ (GH10041)
  • Bug in buffer_rd_bytes src->buffer could be freed more than once if reading failed, causing a segfault (GH12098)
  • Bug in crosstab where arguments with non-overlapping indexes would return a KeyError (GH10291)
  • Bug in DataFrame.apply in which reduction was not being prevented for cases in which dtype was not a numpy dtype (GH12244)
  • Bug when initializing categorical series with a scalar value. (GH12336)
  • Bug when specifying a UTC DatetimeIndex by setting utc=True in .to_datetime (GH11934)
  • Bug when increasing the buffer size of CSV reader in read_csv (GH12494)
  • Bug when setting columns of a DataFrame with duplicate column names (GH12344)

v0.17.1 (November 21, 2015)


We are proud to announce that pandas has become a sponsored project of the (NUMFocus organization). This will help ensure the success of development of pandas as a world-class open-source project.

This is a minor bug-fix release from 0.17.0 and includes a large number of bug fixes along several new features, enhancements, and performance improvements. We recommend that all users upgrade to this version.

Highlights include:

  • Support for Conditional HTML Formatting, see here
  • Releasing the GIL on the csv reader & other ops, see here
  • Fixed regression in DataFrame.drop_duplicates from 0.16.2, causing incorrect results on integer values (GH11376)

New features

Conditional HTML Formatting


This is a new feature and is under active development. We’ll be adding features an possibly making breaking changes in future releases. Feedback is welcome.

We’ve added experimental support for conditional HTML formatting: the visual styling of a DataFrame based on the data. The styling is accomplished with HTML and CSS. Acesses the styler class with the, attribute, an instance of Styler with your data attached.

Here’s a quick example:

In [1]: np.random.seed(123)

In [2]: df = DataFrame(np.random.randn(10, 5), columns=list('abcde'))

In [3]: html ='viridis', low=.5)

We can render the HTML to get the following table.

a b c d e
0 -1.085631 0.997345 0.282978 -1.506295 -0.5786
1 1.651437 -2.426679 -0.428913 1.265936 -0.86674
2 -0.678886 -0.094709 1.49139 -0.638902 -0.443982
3 -0.434351 2.20593 2.186786 1.004054 0.386186
4 0.737369 1.490732 -0.935834 1.175829 -1.253881
5 -0.637752 0.907105 -1.428681 -0.140069 -0.861755
6 -0.255619 -2.798589 -1.771533 -0.699877 0.927462
7 -0.173636 0.002846 0.688223 -0.879536 0.283627
8 -0.805367 -1.727669 -0.3909 0.573806 0.338589
9 -0.01183 2.392365 0.412912 0.978736 2.238143

Styler interacts nicely with the Jupyter Notebook. See the documentation for more.


  • DatetimeIndex now supports conversion to strings with astype(str) (GH10442)

  • Support for compression (gzip/bz2) in pandas.DataFrame.to_csv() (GH7615)

  • pd.read_* functions can now also accept pathlib.Path, or py._path.local.LocalPath objects for the filepath_or_buffer argument. (GH11033) - The DataFrame and Series functions .to_csv(), .to_html() and .to_latex() can now handle paths beginning with tildes (e.g. ~/Documents/) (GH11438)

  • DataFrame now uses the fields of a namedtuple as columns, if columns are not supplied (GH11181)

  • DataFrame.itertuples() now returns namedtuple objects, when possible. (GH11269, GH11625)

  • Added axvlines_kwds to parallel coordinates plot (GH10709)

  • Option to .info() and .memory_usage() to provide for deep introspection of memory consumption. Note that this can be expensive to compute and therefore is an optional parameter. (GH11595)

    In [4]: df = DataFrame({'A' : ['foo']*1000})
    In [5]: df['B'] = df['A'].astype('category')
    # shows the '+' as we have object dtypes
    In [6]:
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 1000 entries, 0 to 999
    Data columns (total 2 columns):
    A    1000 non-null object
    B    1000 non-null category
    dtypes: category(1), object(1)
    memory usage: 8.9+ KB
    # we have an accurate memory assessment (but can be expensive to compute this)
    In [7]:'deep')
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 1000 entries, 0 to 999
    Data columns (total 2 columns):
    A    1000 non-null object
    B    1000 non-null category
    dtypes: category(1), object(1)
    memory usage: 48.0 KB
  • Index now has a fillna method (GH10089)

    In [8]: pd.Index([1, np.nan, 3]).fillna(2)
    Out[8]: Float64Index([1.0, 2.0, 3.0], dtype='float64')
  • Series of type category now make .str.<...> and .dt.<...> accessor methods / properties available, if the categories are of that type. (GH10661)

    In [9]: s = pd.Series(list('aabb')).astype('category')
    In [10]: s
    0    a
    1    a
    2    b
    3    b
    dtype: category
    Categories (2, object): [a, b]
    In [11]: s.str.contains("a")
    0     True
    1     True
    2    False
    3    False
    dtype: bool
    In [12]: date = pd.Series(pd.date_range('1/1/2015', periods=5)).astype('category')
    In [13]: date
    0   2015-01-01
    1   2015-01-02
    2   2015-01-03
    3   2015-01-04
    4   2015-01-05
    dtype: category
    Categories (5, datetime64[ns]): [2015-01-01, 2015-01-02, 2015-01-03, 2015-01-04, 2015-01-05]
    In [14]:
    0    1
    1    2
    2    3
    3    4
    4    5
    dtype: int64
  • pivot_table now has a margins_name argument so you can use something other than the default of ‘All’ (GH3335)

  • Implement export of datetime64[ns, tz] dtypes with a fixed HDF5 store (GH11411)

  • Pretty printing sets (e.g. in DataFrame cells) now uses set literal syntax ({x, y}) instead of Legacy Python syntax (set([x, y])) (GH11215)

  • Improve the error message in when a streaming insert fails (GH11285) and when the DataFrame does not match the schema of the destination table (GH11359)

API changes

  • raise NotImplementedError in Index.shift for non-supported index types (GH8038)
  • min and max reductions on datetime64 and timedelta64 dtyped series now result in NaT and not nan (GH11245).
  • Indexing with a null key will raise a TypeError, instead of a ValueError (GH11356)
  • Series.ptp will now ignore missing values by default (GH11163)


  • The module which implements google-analytics support is deprecated and will be removed in a future version (GH11308)
  • Deprecate the engine keyword in .to_csv(), which will be removed in a future version (GH11274)

Performance Improvements

  • Checking monotonic-ness before sorting on an index (GH11080)
  • Series.dropna performance improvement when its dtype can’t contain NaN (GH11159)
  • Release the GIL on most datetime field operations (e.g. DatetimeIndex.year, Series.dt.year), normalization, and conversion to and from Period, DatetimeIndex.to_period and PeriodIndex.to_timestamp (GH11263)
  • Release the GIL on some rolling algos: rolling_median, rolling_mean, rolling_max, rolling_min, rolling_var, rolling_kurt, rolling_skew (GH11450)
  • Release the GIL when reading and parsing text files in read_csv, read_table (GH11272)
  • Improved performance of rolling_median (GH11450)
  • Improved performance of to_excel (GH11352)
  • Performance bug in repr of Categorical categories, which was rendering the strings before chopping them for display (GH11305)
  • Performance improvement in Categorical.remove_unused_categories, (GH11643).
  • Improved performance of Series constructor with no data and DatetimeIndex (GH11433)
  • Improved performance of shift, cumprod, and cumsum with groupby (GH4095)

Bug Fixes

  • SparseArray.__iter__() now does not cause PendingDeprecationWarning in Python 3.5 (GH11622)
  • Regression from 0.16.2 for output formatting of long floats/nan, restored in (GH11302)
  • Series.sort_index() now correctly handles the inplace option (GH11402)
  • Incorrectly distributed .c file in the build on PyPi when reading a csv of floats and passing na_values=<a scalar> would show an exception (GH11374)
  • Bug in .to_latex() output broken when the index has a name (GH10660)
  • Bug in HDFStore.append with strings whose encoded length exceded the max unencoded length (GH11234)
  • Bug in merging datetime64[ns, tz] dtypes (GH11405)
  • Bug in when comparing with a numpy scalar in a where clause (GH11283)
  • Bug in using DataFrame.ix with a multi-index indexer (GH11372)
  • Bug in date_range with ambigous endpoints (GH11626)
  • Prevent adding new attributes to the accessors .str, .dt and .cat. Retrieving such a value was not possible, so error out on setting it. (GH10673)
  • Bug in tz-conversions with an ambiguous time and .dt accessors (GH11295)
  • Bug in output formatting when using an index of ambiguous times (GH11619)
  • Bug in comparisons of Series vs list-likes (GH11339)
  • Bug in DataFrame.replace with a datetime64[ns, tz] and a non-compat to_replace (GH11326, GH11153)
  • Bug in isnull where numpy.datetime64('NaT') in a numpy.array was not determined to be null(GH11206)
  • Bug in list-like indexing with a mixed-integer Index (GH11320)
  • Bug in pivot_table with margins=True when indexes are of Categorical dtype (GH10993)
  • Bug in DataFrame.plot cannot use hex strings colors (GH10299)
  • Regression in DataFrame.drop_duplicates from 0.16.2, causing incorrect results on integer values (GH11376)
  • Bug in pd.eval where unary ops in a list error (GH11235)
  • Bug in squeeze() with zero length arrays (GH11230, GH8999)
  • Bug in describe() dropping column names for hierarchical indexes (GH11517)
  • Bug in DataFrame.pct_change() not propagating axis keyword on .fillna method (GH11150)
  • Bug in .to_csv() when a mix of integer and string column names are passed as the columns parameter (GH11637)
  • Bug in indexing with a range, (GH11652)
  • Bug in inference of numpy scalars and preserving dtype when setting columns (GH11638)
  • Bug in to_sql using unicode column names giving UnicodeEncodeError with (GH11431).
  • Fix regression in setting of xticks in plot (GH11529).
  • Bug in holiday.dates where observance rules could not be applied to holiday and doc enhancement (GH11477, GH11533)
  • Fix plotting issues when having plain Axes instances instead of SubplotAxes (GH11520, GH11556).
  • Bug in DataFrame.to_latex() produces an extra rule when header=False (GH7124)
  • Bug in df.groupby(...).apply(func) when a func returns a Series containing a new datetimelike column (GH11324)
  • Bug in pandas.json when file to load is big (GH11344)
  • Bugs in to_excel with duplicate columns (GH11007, GH10982, GH10970)
  • Fixed a bug that prevented the construction of an empty series of dtype datetime64[ns, tz] (GH11245).
  • Bug in read_excel with multi-index containing integers (GH11317)
  • Bug in to_excel with openpyxl 2.2+ and merging (GH11408)
  • Bug in DataFrame.to_dict() produces a np.datetime64 object instead of Timestamp when only datetime is present in data (GH11327)
  • Bug in DataFrame.corr() raises exception when computes Kendall correlation for DataFrames with boolean and not boolean columns (GH11560)
  • Bug in the link-time error caused by C inline functions on FreeBSD 10+ (with clang) (GH10510)
  • Bug in DataFrame.to_csv in passing through arguments for formatting MultiIndexes, including date_format (GH7791)
  • Bug in DataFrame.join() with how='right' producing a TypeError (GH11519)
  • Bug in Series.quantile with empty list results has Index with object dtype (GH11588)
  • Bug in pd.merge results in empty Int64Index rather than Index(dtype=object) when the merge result is empty (GH11588)
  • Bug in Categorical.remove_unused_categories when having NaN values (GH11599)
  • Bug in DataFrame.to_sparse() loses column names for MultiIndexes (GH11600)
  • Bug in DataFrame.round() with non-unique column index producing a Fatal Python error (GH11611)
  • Bug in DataFrame.round() with decimals being a non-unique indexed Series producing extra columns (GH11618)

v0.17.0 (October 9, 2015)

This is a major release from 0.16.2 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all users upgrade to this version.


pandas >= 0.17.0 will no longer support compatibility with Python version 3.2 (GH9118)


The package is deprecated and will be replaced by the pandas-datareader package. This will allow the data modules to be independently updated to your pandas installation. The API for pandas-datareader v0.1.1 is exactly the same as in pandas v0.17.0 (GH8961, GH10861).

After installing pandas-datareader, you can easily change your imports:

from import data, wb


from pandas_datareader import data, wb

Highlights include:

  • Release the Global Interpreter Lock (GIL) on some cython operations, see here
  • Plotting methods are now available as attributes of the .plot accessor, see here
  • The sorting API has been revamped to remove some long-time inconsistencies, see here
  • Support for a datetime64[ns] with timezones as a first-class dtype, see here
  • The default for to_datetime will now be to raise when presented with unparseable formats, previously this would return the original input. Also, date parse functions now return consistent results. See here
  • The default for dropna in HDFStore has changed to False, to store by default all rows even if they are all NaN, see here
  • Datetime accessor (dt) now supports Series.dt.strftime to generate formatted strings for datetime-likes, and Series.dt.total_seconds to generate each duration of the timedelta in seconds. See here
  • Period and PeriodIndex can handle multiplied freq like 3D, which corresponding to 3 days span. See here
  • Development installed versions of pandas will now have PEP440 compliant version strings (GH9518)
  • Development support for benchmarking with the Air Speed Velocity library (GH8361)
  • Support for reading SAS xport files, see here
  • Documentation comparing SAS to pandas, see here
  • Removal of the automatic TimeSeries broadcasting, deprecated since 0.8.0, see here
  • Display format with plain text can optionally align with Unicode East Asian Width, see here
  • Compatibility with Python 3.5 (GH11097)
  • Compatibility with matplotlib 1.5.0 (GH11111)

Check the API Changes and deprecations before updating.

New features

Datetime with TZ

We are adding an implementation that natively supports datetime with timezones. A Series or a DataFrame column previously could be assigned a datetime with timezones, and would work as an object dtype. This had performance issues with a large number rows. See the docs for more details. (GH8260, GH10763, GH11034).

The new implementation allows for having a single-timezone across all rows, with operations in a performant manner.

In [1]: df = DataFrame({'A' : date_range('20130101',periods=3),
   ...:                 'B' : date_range('20130101',periods=3,tz='US/Eastern'),
   ...:                 'C' : date_range('20130101',periods=3,tz='CET')})

In [2]: df
           A                         B                         C
0 2013-01-01 2013-01-01 00:00:00-05:00 2013-01-01 00:00:00+01:00
1 2013-01-02 2013-01-02 00:00:00-05:00 2013-01-02 00:00:00+01:00
2 2013-01-03 2013-01-03 00:00:00-05:00 2013-01-03 00:00:00+01:00

In [3]: df.dtypes
A                datetime64[ns]
B    datetime64[ns, US/Eastern]
C           datetime64[ns, CET]
dtype: object
In [4]: df.B
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
Name: B, dtype: datetime64[ns, US/Eastern]

In [5]: df.B.dt.tz_localize(None)
0   2013-01-01
1   2013-01-02
2   2013-01-03
Name: B, dtype: datetime64[ns]

This uses a new-dtype representation as well, that is very similar in look-and-feel to its numpy cousin datetime64[ns]

In [6]: df['B'].dtype
Out[6]: datetime64[ns, US/Eastern]

In [7]: type(df['B'].dtype)
Out[7]: pandas.types.dtypes.DatetimeTZDtype


There is a slightly different string repr for the underlying DatetimeIndex as a result of the dtype changes, but functionally these are the same.

Previous Behavior:

In [1]: pd.date_range('20130101',periods=3,tz='US/Eastern')
Out[1]: DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
                       '2013-01-03 00:00:00-05:00'],
                      dtype='datetime64[ns]', freq='D', tz='US/Eastern')

In [2]: pd.date_range('20130101',periods=3,tz='US/Eastern').dtype
Out[2]: dtype('<M8[ns]')

New Behavior:

In [8]: pd.date_range('20130101',periods=3,tz='US/Eastern')
DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
               '2013-01-03 00:00:00-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq='D')

In [9]: pd.date_range('20130101',periods=3,tz='US/Eastern').dtype
Out[9]: datetime64[ns, US/Eastern]

Releasing the GIL

We are releasing the global-interpreter-lock (GIL) on some cython operations. This will allow other threads to run simultaneously during computation, potentially allowing performance improvements from multi-threading. Notably groupby, nsmallest, value_counts and some indexing operations benefit from this. (GH8882)

For example the groupby expression in the following code will have the GIL released during the factorization step, e.g. df.groupby('key') as well as the .sum() operation.

N = 1000000
ngroups = 10
df = DataFrame({'key' : np.random.randint(0,ngroups,size=N),
                'data' : np.random.randn(N) })

Releasing of the GIL could benefit an application that uses threads for user interactions (e.g. QT), or performing multi-threaded computations. A nice example of a library that can handle these types of computation-in-parallel is the dask library.

Plot submethods

The Series and DataFrame .plot() method allows for customizing plot types by supplying the kind keyword arguments. Unfortunately, many of these kinds of plots use different required and optional keyword arguments, which makes it difficult to discover what any given plot kind uses out of the dozens of possible arguments.

To alleviate this issue, we have added a new, optional plotting interface, which exposes each kind of plot as a method of the .plot attribute. Instead of writing series.plot(kind=<kind>, ...), you can now also use series.plot.<kind>(...):

In [10]: df = pd.DataFrame(np.random.rand(10, 2), columns=['a', 'b'])

In [11]:

As a result of this change, these methods are now all discoverable via tab-completion:

In [12]: df.plot.<TAB>
df.plot.area     df.plot.barh     df.plot.density  df.plot.hist     df.plot.line     df.plot.scatter      df.plot.hexbin   df.plot.kde      df.plot.pie

Each method signature only includes relevant arguments. Currently, these are limited to required arguments, but in the future these will include optional arguments, as well. For an overview, see the new Plotting API documentation.

Additional methods for dt accessor


We are now supporting a Series.dt.strftime method for datetime-likes to generate a formatted string (GH10110). Examples:

# DatetimeIndex
In [13]: s = pd.Series(pd.date_range('20130101', periods=4))

In [14]: s
0   2013-01-01
1   2013-01-02
2   2013-01-03
3   2013-01-04
dtype: datetime64[ns]

In [15]: s.dt.strftime('%Y/%m/%d')
0    2013/01/01
1    2013/01/02
2    2013/01/03
3    2013/01/04
dtype: object
# PeriodIndex
In [16]: s = pd.Series(pd.period_range('20130101', periods=4))

In [17]: s
0   2013-01-01
1   2013-01-02
2   2013-01-03
3   2013-01-04
dtype: object

In [18]: s.dt.strftime('%Y/%m/%d')
0    2013/01/01
1    2013/01/02
2    2013/01/03
3    2013/01/04
dtype: object

The string format is as the python standard library and details can be found here


pd.Series of type timedelta64 has new method .dt.total_seconds() returning the duration of the timedelta in seconds (GH10817)

# TimedeltaIndex
In [19]: s = pd.Series(pd.timedelta_range('1 minutes', periods=4))

In [20]: s
0   0 days 00:01:00
1   1 days 00:01:00
2   2 days 00:01:00
3   3 days 00:01:00
dtype: timedelta64[ns]

In [21]: s.dt.total_seconds()
0        60.0
1     86460.0
2    172860.0
3    259260.0
dtype: float64

Period Frequency Enhancement

Period, PeriodIndex and period_range can now accept multiplied freq. Also, Period.freq and PeriodIndex.freq are now stored as a DateOffset instance like DatetimeIndex, and not as str (GH7811)

A multiplied freq represents a span of corresponding length. The example below creates a period of 3 days. Addition and subtraction will shift the period by its span.

In [22]: p = pd.Period('2015-08-01', freq='3D')

In [23]: p
Out[23]: Period('2015-08-01', '3D')

In [24]: p + 1
Out[24]: Period('2015-08-04', '3D')

In [25]: p - 2
Out[25]: Period('2015-07-26', '3D')

In [26]: p.to_timestamp()
Out[26]: Timestamp('2015-08-01 00:00:00')

In [27]: p.to_timestamp(how='E')
Out[27]: Timestamp('2015-08-03 00:00:00')

You can use the multiplied freq in PeriodIndex and period_range.

In [28]: idx = pd.period_range('2015-08-01', periods=4, freq='2D')

In [29]: idx
Out[29]: PeriodIndex(['2015-08-01', '2015-08-03', '2015-08-05', '2015-08-07'], dtype='int64', freq='2D')

In [30]: idx + 1
Out[30]: PeriodIndex(['2015-08-03', '2015-08-05', '2015-08-07', '2015-08-09'], dtype='int64', freq='2D')

Support for SAS XPORT files

read_sas() provides support for reading SAS XPORT format files. (GH4052).

df = pd.read_sas('sas_xport.xpt')

It is also possible to obtain an iterator and read an XPORT file incrementally.

for df in pd.read_sas('sas_xport.xpt', chunksize=10000)

See the docs for more details.

Support for Math Functions in .eval()

eval() now supports calling math functions (GH4893)

df = pd.DataFrame({'a': np.random.randn(10)})
df.eval("b = sin(a)")

The support math functions are sin, cos, exp, log, expm1, log1p, sqrt, sinh, cosh, tanh, arcsin, arccos, arctan, arccosh, arcsinh, arctanh, abs and arctan2.

These functions map to the intrinsics for the NumExpr engine. For the Python engine, they are mapped to NumPy calls.

Changes to Excel with MultiIndex

In version 0.16.2 a DataFrame with MultiIndex columns could not be written to Excel via to_excel. That functionality has been added (GH10564), along with updating read_excel so that the data can be read back with, no loss of information, by specifying which columns/rows make up the MultiIndex in the header and index_col parameters (GH4679)

See the documentation for more details.

In [31]: df = pd.DataFrame([[1,2,3,4], [5,6,7,8]],
   ....:                   columns = pd.MultiIndex.from_product([['foo','bar'],['a','b']],
   ....:                                                        names = ['col1', 'col2']),
   ....:                   index = pd.MultiIndex.from_product([['j'], ['l', 'k']],
   ....:                                                      names = ['i1', 'i2']))

In [32]: df
col1  foo    bar   
col2    a  b   a  b
i1 i2              
j  l    1  2   3  4
   k    5  6   7  8

In [33]: df.to_excel('test.xlsx')

In [34]: df = pd.read_excel('test.xlsx', header=[0,1], index_col=[0,1])

In [35]: df
col1  foo    bar   
col2    a  b   a  b
i1 i2              
j  l    1  2   3  4
   k    5  6   7  8

Previously, it was necessary to specify the has_index_names argument in read_excel, if the serialized data had index names. For version 0.17.0 the ouptput format of to_excel has been changed to make this keyword unnecessary - the change is shown below.






Excel files saved in version 0.16.2 or prior that had index names will still able to be read in, but the has_index_names argument must specified to True.

Google BigQuery Enhancements

  • Added ability to automatically create a table/dataset using the function if the destination table/dataset does not exist. (GH8325, GH11121).
  • Added ability to replace an existing table and schema when calling the function via the if_exists argument. See the docs for more details (GH8325).
  • InvalidColumnOrder and InvalidPageToken in the gbq module will raise ValueError instead of IOError.
  • The generate_bq_schema() function is now deprecated and will be removed in a future version (GH11121)
  • The gbq module will now support Python 3 (GH11094).

Display Alignment with Unicode East Asian Width


Enabling this option will affect the performance for printing of DataFrame and Series (about 2 times slower). Use only when it is actually required.

Some East Asian countries use Unicode characters its width is corresponding to 2 alphabets. If a DataFrame or Series contains these characters, the default output cannot be aligned properly. The following options are added to enable precise handling for these characters.

  • display.unicode.east_asian_width: Whether to use the Unicode East Asian Width to calculate the display text width. (GH2612)
  • display.unicode.ambiguous_as_wide: Whether to handle Unicode characters belong to Ambiguous as Wide. (GH11102)
In [36]: df = pd.DataFrame({u'国籍': ['UK', u'日本'], u'名前': ['Alice', u'しのぶ']})

In [37]: df;
In [38]: pd.set_option('display.unicode.east_asian_width', True)

In [39]: df;

For further details, see here

Other enhancements

  • Support for openpyxl >= 2.2. The API for style support is now stable (GH10125)

  • merge now accepts the argument indicator which adds a Categorical-type column (by default called _merge) to the output object that takes on the values (GH8790)

    Observation Origin _merge value
    Merge key only in 'left' frame left_only
    Merge key only in 'right' frame right_only
    Merge key in both frames both
    In [40]: df1 = pd.DataFrame({'col1':[0,1], 'col_left':['a','b']})
    In [41]: df2 = pd.DataFrame({'col1':[1,2,2],'col_right':[2,2,2]})
    In [42]: pd.merge(df1, df2, on='col1', how='outer', indicator=True)
       col1 col_left  col_right      _merge
    0   0.0        a        NaN   left_only
    1   1.0        b        2.0        both
    2   2.0      NaN        2.0  right_only
    3   2.0      NaN        2.0  right_only

    For more, see the updated docs

  • pd.to_numeric is a new function to coerce strings to numbers (possibly with coercion) (GH11133)

  • pd.merge will now allow duplicate column names if they are not merged upon (GH10639).

  • pd.pivot will now allow passing index as None (GH3962).

  • pd.concat will now use existing Series names if provided (GH10698).

    In [43]: foo = pd.Series([1,2], name='foo')
    In [44]: bar = pd.Series([1,2])
    In [45]: baz = pd.Series([4,5])

    Previous Behavior:

    In [1] pd.concat([foo, bar, baz], 1)
          0  1  2
       0  1  1  4
       1  2  2  5

    New Behavior:

    In [46]: pd.concat([foo, bar, baz], 1)
       foo  0  1
    0    1  1  4
    1    2  2  5
  • DataFrame has gained the nlargest and nsmallest methods (GH10393)

  • Add a limit_direction keyword argument that works with limit to enable interpolate to fill NaN values forward, backward, or both (GH9218, GH10420, GH11115)

    In [47]: ser = pd.Series([np.nan, np.nan, 5, np.nan, np.nan, np.nan, 13])
    In [48]: ser.interpolate(limit=1, limit_direction='both')
    0     NaN
    1     5.0
    2     5.0
    3     7.0
    4     NaN
    5    11.0
    6    13.0
    dtype: float64
  • Added a DataFrame.round method to round the values to a variable number of decimal places (GH10568).

    In [49]: df = pd.DataFrame(np.random.random([3, 3]), columns=['A', 'B', 'C'],
       ....: index=['first', 'second', 'third'])
    In [50]: df
                   A         B         C
    first   0.342764  0.304121  0.417022
    second  0.681301  0.875457  0.510422
    third   0.669314  0.585937  0.624904
    In [51]: df.round(2)
               A     B     C
    first   0.34  0.30  0.42
    second  0.68  0.88  0.51
    third   0.67  0.59  0.62
    In [52]: df.round({'A': 0, 'C': 2})
              A         B     C
    first   0.0  0.304121  0.42
    second  1.0  0.875457  0.51
    third   1.0  0.585937  0.62
  • drop_duplicates and duplicated now accept a keep keyword to target first, last, and all duplicates. The take_last keyword is deprecated, see here (GH6511, GH8505)

    In [53]: s = pd.Series(['A', 'B', 'C', 'A', 'B', 'D'])
    In [54]: s.drop_duplicates()
    0    A
    1    B
    2    C
    5    D
    dtype: object
    In [55]: s.drop_duplicates(keep='last')
    2    C
    3    A
    4    B
    5    D
    dtype: object
    In [56]: s.drop_duplicates(keep=False)
    2    C
    5    D
    dtype: object
  • Reindex now has a tolerance argument that allows for finer control of Limits on filling while reindexing (GH10411):

    In [57]: df = pd.DataFrame({'x': range(5),
       ....:                    't': pd.date_range('2000-01-01', periods=5)})
    In [58]: df.reindex([0.1, 1.9, 3.5],
       ....:            method='nearest',
       ....:            tolerance=0.2)
                 t    x
    0.1 2000-01-01  0.0
    1.9 2000-01-03  2.0
    3.5        NaT  NaN

    When used on a DatetimeIndex, TimedeltaIndex or PeriodIndex, tolerance will coerced into a Timedelta if possible. This allows you to specify tolerance with a string:

    In [59]: df = df.set_index('t')
    In [60]: df.reindex(pd.to_datetime(['1999-12-31']),
       ....:            method='nearest',
       ....:            tolerance='1 day')
    1999-12-31  0

    tolerance is also exposed by the lower level Index.get_indexer and Index.get_loc methods.

  • Added functionality to use the base argument when resampling a TimeDeltaIndex (GH10530)

  • DatetimeIndex can be instantiated using strings contains NaT (GH7599)

  • to_datetime can now accept the yearfirst keyword (GH7599)

  • pandas.tseries.offsets larger than the Day offset can now be used with a Series for addition/subtraction (GH10699). See the docs for more details.

  • pd.Timedelta.total_seconds() now returns Timedelta duration to ns precision (previously microsecond precision) (GH10939)

  • PeriodIndex now supports arithmetic with np.ndarray (GH10638)

  • Support pickling of Period objects (GH10439)

  • .as_blocks will now take a copy optional argument to return a copy of the data, default is to copy (no change in behavior from prior versions), (GH9607)

  • regex argument to DataFrame.filter now handles numeric column names instead of raising ValueError (GH10384).

  • Enable reading gzip compressed files via URL, either by explicitly setting the compression parameter or by inferring from the presence of the HTTP Content-Encoding header in the response (GH8685)

  • Enable writing Excel files in memory using StringIO/BytesIO (GH7074)

  • Enable serialization of lists and dicts to strings in ExcelWriter (GH8188)

  • SQL io functions now accept a SQLAlchemy connectable. (GH7877)

  • pd.read_sql and to_sql can accept database URI as con parameter (GH10214)

  • read_sql_table will now allow reading from views (GH10750).

  • Enable writing complex values to HDFStores when using the table format (GH10447)

  • Enable pd.read_hdf to be used without specifying a key when the HDF file contains a single dataset (GH10443)

  • pd.read_stata will now read Stata 118 type files. (GH9882)

  • msgpack submodule has been updated to 0.4.6 with backward compatibility (GH10581)

  • DataFrame.to_dict now accepts orient='index' keyword argument (GH10844).

  • DataFrame.apply will return a Series of dicts if the passed function returns a dict and reduce=True (GH8735).

  • Allow passing kwargs to the interpolation methods (GH10378).

  • Improved error message when concatenating an empty iterable of Dataframe objects (GH9157)

  • pd.read_csv can now read bz2-compressed files incrementally, and the C parser can read bz2-compressed files from AWS S3 (GH11070, GH11072).

  • In pd.read_csv, recognize s3n:// and s3a:// URLs as designating S3 file storage (GH11070, GH11071).

  • Read CSV files from AWS S3 incrementally, instead of first downloading the entire file. (Full file download still required for compressed files in Python 2.) (GH11070, GH11073)

  • pd.read_csv is now able to infer compression type for files read from AWS S3 storage (GH11070, GH11074).

Backwards incompatible API changes

Changes to sorting API

The sorting API has had some longtime inconsistencies. (GH9816, GH8239).

Here is a summary of the API PRIOR to 0.17.0:

  • Series.sort is INPLACE while DataFrame.sort returns a new object.
  • Series.order returns a new object
  • It was possible to use Series/DataFrame.sort_index to sort by values by passing the by keyword.
  • Series/DataFrame.sortlevel worked only on a MultiIndex for sorting by index.

To address these issues, we have revamped the API:

  • We have introduced a new method, DataFrame.sort_values(), which is the merger of DataFrame.sort(), Series.sort(), and Series.order(), to handle sorting of values.
  • The existing methods Series.sort(), Series.order(), and DataFrame.sort() have been deprecated and will be removed in a future version.
  • The by argument of DataFrame.sort_index() has been deprecated and will be removed in a future version.
  • The existing method .sort_index() will gain the level keyword to enable level sorting.

We now have two distinct and non-overlapping methods of sorting. A * marks items that will show a FutureWarning.

To sort by the values:

Previous Replacement
* Series.order() Series.sort_values()
* Series.sort() Series.sort_values(inplace=True)
* DataFrame.sort(columns=...) DataFrame.sort_values(by=...)

To sort by the index:

Previous Replacement
Series.sort_index() Series.sort_index()
Series.sortlevel(level=...) Series.sort_index(level=...)
DataFrame.sort_index() DataFrame.sort_index()
DataFrame.sortlevel(level=...) DataFrame.sort_index(level=...)
* DataFrame.sort() DataFrame.sort_index()

We have also deprecated and changed similar methods in two Series-like classes, Index and Categorical.

Previous Replacement
* Index.order() Index.sort_values()
* Categorical.order() Categorical.sort_values()

Changes to to_datetime and to_timedelta

Error handling

The default for pd.to_datetime error handling has changed to errors='raise'. In prior versions it was errors='ignore'. Furthermore, the coerce argument has been deprecated in favor of errors='coerce'. This means that invalid parsing will raise rather that return the original input as in previous versions. (GH10636)

Previous Behavior:

In [2]: pd.to_datetime(['2009-07-31', 'asd'])
Out[2]: array(['2009-07-31', 'asd'], dtype=object)

New Behavior:

In [3]: pd.to_datetime(['2009-07-31', 'asd'])
ValueError: Unknown string format

Of course you can coerce this as well.

In [61]: to_datetime(['2009-07-31', 'asd'], errors='coerce')
Out[61]: DatetimeIndex(['2009-07-31', 'NaT'], dtype='datetime64[ns]', freq=None)

To keep the previous behavior, you can use errors='ignore':

In [62]: to_datetime(['2009-07-31', 'asd'], errors='ignore')
Out[62]: array(['2009-07-31', 'asd'], dtype=object)

Furthermore, pd.to_timedelta has gained a similar API, of errors='raise'|'ignore'|'coerce', and the coerce keyword has been deprecated in favor of errors='coerce'.

Consistent Parsing

The string parsing of to_datetime, Timestamp and DatetimeIndex has been made consistent. (GH7599)

Prior to v0.17.0, Timestamp and to_datetime may parse year-only datetime-string incorrectly using today’s date, otherwise DatetimeIndex uses the beginning of the year. Timestamp and to_datetime may raise ValueError in some types of datetime-string which DatetimeIndex can parse, such as a quarterly string.

Previous Behavior:

In [1]: Timestamp('2012Q2')
ValueError: Unable to parse 2012Q2

# Results in today's date.
In [2]: Timestamp('2014')
Out [2]: 2014-08-12 00:00:00

v0.17.0 can parse them as below. It works on DatetimeIndex also.

New Behavior:

In [63]: Timestamp('2012Q2')
Out[63]: Timestamp('2012-04-01 00:00:00')

In [64]: Timestamp('2014')
Out[64]: Timestamp('2014-01-01 00:00:00')

In [65]: DatetimeIndex(['2012Q2', '2014'])
Out[65]: DatetimeIndex(['2012-04-01', '2014-01-01'], dtype='datetime64[ns]', freq=None)


If you want to perform calculations based on today’s date, use and pandas.tseries.offsets.

In [66]: import pandas.tseries.offsets as offsets

In [67]:
Out[67]: Timestamp('2016-05-03 09:45:09.916925')

In [68]: + offsets.DateOffset(years=1)
Out[68]: Timestamp('2017-05-03 09:45:09.918665')

Changes to Index Comparisons

Operator equal on Index should behavior similarly to Series (GH9947, GH10637)

Starting in v0.17.0, comparing Index objects of different lengths will raise a ValueError. This is to be consistent with the behavior of Series.

Previous Behavior:

In [2]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5])
Out[2]: array([ True, False, False], dtype=bool)

In [3]: pd.Index([1, 2, 3]) == pd.Index([2])
Out[3]: array([False,  True, False], dtype=bool)

In [4]: pd.Index([1, 2, 3]) == pd.Index([1, 2])
Out[4]: False

New Behavior:

In [8]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5])
Out[8]: array([ True, False, False], dtype=bool)

In [9]: pd.Index([1, 2, 3]) == pd.Index([2])
ValueError: Lengths must match to compare

In [10]: pd.Index([1, 2, 3]) == pd.Index([1, 2])
ValueError: Lengths must match to compare

Note that this is different from the numpy behavior where a comparison can be broadcast:

In [69]: np.array([1, 2, 3]) == np.array([1])
Out[69]: array([ True, False, False], dtype=bool)

or it can return False if broadcasting can not be done:

In [70]: np.array([1, 2, 3]) == np.array([1, 2])
Out[70]: False

Changes to Boolean Comparisons vs. None

Boolean comparisons of a Series vs None will now be equivalent to comparing with np.nan, rather than raise TypeError. (GH1079).

In [71]: s = Series(range(3))

In [72]: s.iloc[1] = None

In [73]: s
0    0.0
1    NaN
2    2.0
dtype: float64

Previous Behavior:

In [5]: s==None
TypeError: Could not compare <type 'NoneType'> type with Series

New Behavior:

In [74]: s==None
0    False
1    False
2    False
dtype: bool

Usually you simply want to know which values are null.

In [75]: s.isnull()
0    False
1     True
2    False
dtype: bool


You generally will want to use isnull/notnull for these types of comparisons, as isnull/notnull tells you which elements are null. One has to be mindful that nan's don’t compare equal, but None's do. Note that Pandas/numpy uses the fact that np.nan != np.nan, and treats None like np.nan.

In [76]: None == None
Out[76]: True

In [77]: np.nan == np.nan
Out[77]: False

HDFStore dropna behavior

The default behavior for HDFStore write functions with format='table' is now to keep rows that are all missing. Previously, the behavior was to drop rows that were all missing save the index. The previous behavior can be replicated using the dropna=True option. (GH9382)

Previous Behavior:

In [78]: df_with_missing = pd.DataFrame({'col1':[0, np.nan, 2],
   ....:                                 'col2':[1, np.nan, np.nan]})

In [79]: df_with_missing
   col1  col2
0   0.0   1.0
1   NaN   NaN
2   2.0   NaN
In [27]:

In [28]: pd.read_hdf('file.h5', 'df_with_missing')

Out [28]:
      col1  col2
  0     0     1
  2     2   NaN

New Behavior:

In [80]: df_with_missing.to_hdf('file.h5',
   ....:                        'df_with_missing',
   ....:                         format='table',
   ....:                         mode='w')

In [81]: pd.read_hdf('file.h5', 'df_with_missing')
   col1  col2
0   0.0   1.0
1   NaN   NaN
2   2.0   NaN

See the docs for more details.

Changes to display.precision option

The display.precision option has been clarified to refer to decimal places (GH10451).

Earlier versions of pandas would format floating point numbers to have one less decimal place than the value in display.precision.

In [1]: pd.set_option('display.precision', 2)

In [2]: pd.DataFrame({'x': [123.456789]})
0  123.5

If interpreting precision as “significant figures” this did work for scientific notation but that same interpretation did not work for values with standard formatting. It was also out of step with how numpy handles formatting.

Going forward the value of display.precision will directly control the number of places after the decimal, for regular formatting as well as scientific notation, similar to how numpy’s precision print option works.

In [82]: pd.set_option('display.precision', 2)

In [83]: pd.DataFrame({'x': [123.456789]})
0  123.46

To preserve output behavior with prior versions the default value of display.precision has been reduced to 6 from 7.

Changes to Categorical.unique

Categorical.unique now returns new Categoricals with categories and codes that are unique, rather than returning np.array (GH10508)

  • unordered category: values and categories are sorted by appearance order.
  • ordered category: values are sorted by appearance order, categories keep existing order.
In [84]: cat = pd.Categorical(['C', 'A', 'B', 'C'],
   ....:                      categories=['A', 'B', 'C'],
   ....:                      ordered=True)

In [85]: cat
[C, A, B, C]
Categories (3, object): [A < B < C]

In [86]: cat.unique()
[C, A, B]
Categories (3, object): [A < B < C]

In [87]: cat = pd.Categorical(['C', 'A', 'B', 'C'],
   ....:                      categories=['A', 'B', 'C'])

In [88]: cat
[C, A, B, C]
Categories (3, object): [A, B, C]

In [89]: cat.unique()
[C, A, B]
Categories (3, object): [C, A, B]

Changes to bool passed as header in Parsers

In earlier versions of pandas, if a bool was passed the header argument of read_csv, read_excel, or read_html it was implicitly converted to an integer, resulting in header=0 for False and header=1 for True (GH6113)

A bool input to header will now raise a TypeError

In [29]: df = pd.read_csv('data.csv', header=False)
TypeError: Passing a bool to header is invalid. Use header=None for no header or
header=int or list-like of ints to specify the row(s) making up the column names

Other API Changes

  • Line and kde plot with subplots=True now uses default colors, not all black. Specify color='k' to draw all lines in black (GH9894)

  • Calling the .value_counts() method on a Series with a categorical dtype now returns a Series with a CategoricalIndex (GH10704)

  • The metadata properties of subclasses of pandas objects will now be serialized (GH10553).

  • groupby using Categorical follows the same rule as Categorical.unique described above (GH10508)

  • When constructing DataFrame with an array of complex64 dtype previously meant the corresponding column was automatically promoted to the complex128 dtype. Pandas will now preserve the itemsize of the input for complex data (GH10952)

  • some numeric reduction operators would return ValueError, rather than TypeError on object types that includes strings and numbers (GH11131)

  • Passing currently unsupported chunksize argument to read_excel or ExcelFile.parse will now raise NotImplementedError (GH8011)

  • Allow an ExcelFile object to be passed into read_excel (GH11198)

  • DatetimeIndex.union does not infer freq if self and the input have None as freq (GH11086)

  • NaT‘s methods now either raise ValueError, or return np.nan or NaT (GH9513)

    Behavior Methods
    return np.nan weekday, isoweekday
    return NaT date, now, replace, to_datetime, today
    return np.datetime64('NaT') to_datetime64 (unchanged)
    raise ValueError All other public methods (names not beginning with underscores)


  • For Series the following indexing functions are deprecated (GH10177).

    Deprecated Function Replacement
    .irow(i) .iloc[i] or .iat[i]
    .iget(i) .iloc[i] or .iat[i]
    .iget_value(i) .iloc[i] or .iat[i]
  • For DataFrame the following indexing functions are deprecated (GH10177).

    Deprecated Function Replacement
    .irow(i) .iloc[i]
    .iget_value(i, j) .iloc[i, j] or .iat[i, j]
    .icol(j) .iloc[:, j]


These indexing function have been deprecated in the documentation since 0.11.0.

  • was deprecated to make Categorical more numpy.ndarray like. Use Series(cat, name="whatever") instead (GH10482).
  • Setting missing values (NaN) in a Categorical‘s categories will issue a warning (GH10748). You can still have missing values in the values.
  • drop_duplicates and duplicated‘s take_last keyword was deprecated in favor of keep. (GH6511, GH8505)
  • Series.nsmallest and nlargest‘s take_last keyword was deprecated in favor of keep. (GH10792)
  • DataFrame.combineAdd and DataFrame.combineMult are deprecated. They can easily be replaced by using the add and mul methods: DataFrame.add(other, fill_value=0) and DataFrame.mul(other, fill_value=1.) (GH10735).
  • TimeSeries deprecated in favor of Series (note that this has been an alias since 0.13.0), (GH10890)
  • SparsePanel deprecated and will be removed in a future version (GH11157).
  • Series.is_time_series deprecated in favor of Series.index.is_all_dates (GH11135)
  • Legacy offsets (like 'A@JAN') listed in here are deprecated (note that this has been alias since 0.8.0), (GH10878)
  • WidePanel deprecated in favor of Panel, LongPanel in favor of DataFrame (note these have been aliases since < 0.11.0), (GH10892)
  • DataFrame.convert_objects has been deprecated in favor of type-specific functions pd.to_datetime, pd.to_timestamp and pd.to_numeric (new in 0.17.0) (GH11133).

Removal of prior version deprecations/changes

  • Removal of na_last parameters from Series.order() and Series.sort(), in favor of na_position. (GH5231)

  • Remove of percentile_width from .describe(), in favor of percentiles. (GH7088)

  • Removal of colSpace parameter from DataFrame.to_string(), in favor of col_space, circa 0.8.0 version.

  • Removal of automatic time-series broadcasting (GH2304)

    In [90]: np.random.seed(1234)
    In [91]: df = DataFrame(np.random.randn(5,2),columns=list('AB'),index=date_range('20130101',periods=5))
    In [92]: df
                       A         B
    2013-01-01  0.471435 -1.190976
    2013-01-02  1.432707 -0.312652
    2013-01-03 -0.720589  0.887163
    2013-01-04  0.859588 -0.636524
    2013-01-05  0.015696 -2.242685


    In [3]: df + df.A
    FutureWarning: TimeSeries broadcasting along DataFrame index by default is deprecated.
    Please use DataFrame.<op> to explicitly broadcast arithmetic operations along the index
                        A         B
    2013-01-01  0.942870 -0.719541
    2013-01-02  2.865414  1.120055
    2013-01-03 -1.441177  0.166574
    2013-01-04  1.719177  0.223065
    2013-01-05  0.031393 -2.226989


    In [93]: df.add(df.A,axis='index')
                       A         B
    2013-01-01  0.942870 -0.719541
    2013-01-02  2.865414  1.120055
    2013-01-03 -1.441177  0.166574
    2013-01-04  1.719177  0.223065
    2013-01-05  0.031393 -2.226989
  • Remove table keyword in HDFStore.put/append, in favor of using format= (GH4645)

  • Remove kind in read_excel/ExcelFile as its unused (GH4712)

  • Remove infer_type keyword from pd.read_html as its unused (GH4770, GH7032)

  • Remove offset and timeRule keywords from Series.tshift/shift, in favor of freq (GH4853, GH4864)

  • Remove pd.load/ aliases in favor of pd.to_pickle/pd.read_pickle (GH3787)

Performance Improvements

  • Development support for benchmarking with the Air Speed Velocity library (GH8361)
  • Added vbench benchmarks for alternative ExcelWriter engines and reading Excel files (GH7171)
  • Performance improvements in Categorical.value_counts (GH10804)
  • Performance improvements in SeriesGroupBy.nunique and SeriesGroupBy.value_counts and SeriesGroupby.transform (GH10820, GH11077)
  • Performance improvements in DataFrame.drop_duplicates with integer dtypes (GH10917)
  • Performance improvements in DataFrame.duplicated with wide frames. (GH10161, GH11180)
  • 4x improvement in timedelta string parsing (GH6755, GH10426)
  • 8x improvement in timedelta64 and datetime64 ops (GH6755)
  • Significantly improved performance of indexing MultiIndex with slicers (GH10287)
  • 8x improvement in iloc using list-like input (GH10791)
  • Improved performance of Series.isin for datetimelike/integer Series (GH10287)
  • 20x improvement in concat of Categoricals when categories are identical (GH10587)
  • Improved performance of to_datetime when specified format string is ISO8601 (GH10178)
  • 2x improvement of Series.value_counts for float dtype (GH10821)
  • Enable infer_datetime_format in to_datetime when date components do not have 0 padding (GH11142)
  • Regression from 0.16.1 in constructing DataFrame from nested dictionary (GH11084)
  • Performance improvements in addition/subtraction operations for DateOffset with Series or DatetimeIndex (GH10744, GH11205)

Bug Fixes

  • Bug in incorrection computation of .mean() on timedelta64[ns] because of overflow (GH9442)
  • Bug in .isin on older numpies (:issue: 11232)
  • Bug in DataFrame.to_html(index=False) renders unnecessary name row (GH10344)
  • Bug in DataFrame.to_latex() the column_format argument could not be passed (GH9402)
  • Bug in DatetimeIndex when localizing with NaT (GH10477)
  • Bug in Series.dt ops in preserving meta-data (GH10477)
  • Bug in preserving NaT when passed in an otherwise invalid to_datetime construction (GH10477)
  • Bug in DataFrame.apply when function returns categorical series. (GH9573)
  • Bug in to_datetime with invalid dates and formats supplied (GH10154)
  • Bug in Index.drop_duplicates dropping name(s) (GH10115)
  • Bug in Series.quantile dropping name (GH10881)
  • Bug in pd.Series when setting a value on an empty Series whose index has a frequency. (GH10193)
  • Bug in pd.Series.interpolate with invalid order keyword values. (GH10633)
  • Bug in DataFrame.plot raises ValueError when color name is specified by multiple characters (GH10387)
  • Bug in Index construction with a mixed list of tuples (GH10697)
  • Bug in DataFrame.reset_index when index contains NaT. (GH10388)
  • Bug in ExcelReader when worksheet is empty (GH6403)
  • Bug in BinGrouper.group_info where returned values are not compatible with base class (GH10914)
  • Bug in clearing the cache on DataFrame.pop and a subsequent inplace op (GH10912)
  • Bug in indexing with a mixed-integer Index causing an ImportError (GH10610)
  • Bug in Series.count when index has nulls (GH10946)
  • Bug in pickling of a non-regular freq DatetimeIndex (GH11002)
  • Bug causing DataFrame.where to not respect the axis parameter when the frame has a symmetric shape. (GH9736)
  • Bug in Table.select_column where name is not preserved (GH10392)
  • Bug in offsets.generate_range where start and end have finer precision than offset (GH9907)
  • Bug in pd.rolling_* where would be lost in the output (GH10565)
  • Bug in stack when index or columns are not unique. (GH10417)
  • Bug in setting a Panel when an axis has a multi-index (GH10360)
  • Bug in USFederalHolidayCalendar where USMemorialDay and USMartinLutherKingJr were incorrect (GH10278 and GH9760 )
  • Bug in .sample() where returned object, if set, gives unnecessary SettingWithCopyWarning (GH10738)
  • Bug in .sample() where weights passed as Series were not aligned along axis before being treated positionally, potentially causing problems if weight indices were not aligned with sampled object. (GH10738)
  • Regression fixed in (GH9311, GH6620, GH9345), where groupby with a datetime-like converting to float with certain aggregators (GH10979)
  • Bug in DataFrame.interpolate with axis=1 and inplace=True (GH10395)
  • Bug in io.sql.get_schema when specifying multiple columns as primary key (GH10385).
  • Bug in groupby(sort=False) with datetime-like Categorical raises ValueError (GH10505)
  • Bug in groupby(axis=1) with filter() throws IndexError (GH11041)
  • Bug in test_categorical on big-endian builds (GH10425)
  • Bug in Series.shift and DataFrame.shift not supporting categorical data (GH9416)
  • Bug in using categorical Series raises AttributeError (GH10324)
  • Bug in MultiIndex.get_level_values including Categorical raises AttributeError (GH10460)
  • Bug in pd.get_dummies with sparse=True not returning SparseDataFrame (GH10531)
  • Bug in Index subtypes (such as PeriodIndex) not returning their own type for .drop and .insert methods (GH10620)
  • Bug in algos.outer_join_indexer when right array is empty (GH10618)
  • Bug in filter (regression from 0.16.0) and transform when grouping on multiple keys, one of which is datetime-like (GH10114)
  • Bug in to_datetime and to_timedelta causing Index name to be lost (GH10875)
  • Bug in len(DataFrame.groupby) causing IndexError when there’s a column containing only NaNs (:issue: 11016)
  • Bug that caused segfault when resampling an empty Series (GH10228)
  • Bug in DatetimeIndex and PeriodIndex.value_counts resets name from its result, but retains in result’s Index. (GH10150)
  • Bug in pd.eval using numexpr engine coerces 1 element numpy array to scalar (GH10546)
  • Bug in pd.concat with axis=0 when column is of dtype category (GH10177)
  • Bug in read_msgpack where input type is not always checked (GH10369, GH10630)
  • Bug in pd.read_csv with kwargs index_col=False, index_col=['a', 'b'] or dtype (GH10413, GH10467, GH10577)
  • Bug in Series.from_csv with header kwarg not setting the or the (GH10483)
  • Bug in groupby.var which caused variance to be inaccurate for small float values (GH10448)
  • Bug in Series.plot(kind='hist') Y Label not informative (GH10485)
  • Bug in read_csv when using a converter which generates a uint8 type (GH9266)
  • Bug causes memory leak in time-series line and area plot (GH9003)
  • Bug when setting a Panel sliced along the major or minor axes when the right-hand side is a DataFrame (GH11014)
  • Bug that returns None and does not raise NotImplementedError when operator functions (e.g. .add) of Panel are not implemented (GH7692)
  • Bug in line and kde plot cannot accept multiple colors when subplots=True (GH9894)
  • Bug in DataFrame.plot raises ValueError when color name is specified by multiple characters (GH10387)
  • Bug in left and right align of Series with MultiIndex may be inverted (GH10665)
  • Bug in left and right join of with MultiIndex may be inverted (GH10741)
  • Bug in read_stata when reading a file with a different order set in columns (GH10757)
  • Bug in Categorical may not representing properly when category contains tz or Period (GH10713)
  • Bug in Categorical.__iter__ may not returning correct datetime and Period (GH10713)
  • Bug in indexing with a PeriodIndex on an object with a PeriodIndex (GH4125)
  • Bug in read_csv with engine='c': EOF preceded by a comment, blank line, etc. was not handled correctly (GH10728, GH10548)
  • Reading “famafrench” data via DataReader results in HTTP 404 error because of the website url is changed (GH10591).
  • Bug in read_msgpack where DataFrame to decode has duplicate column names (GH9618)
  • Bug in io.common.get_filepath_or_buffer which caused reading of valid S3 files to fail if the bucket also contained keys for which the user does not have read permission (GH10604)
  • Bug in vectorised setting of timestamp columns with python and numpy datetime64 (GH10408, GH10412)
  • Bug in Index.take may add unnecessary freq attribute (GH10791)
  • Bug in merge with empty DataFrame may raise IndexError (GH10824)
  • Bug in to_latex where unexpected keyword argument for some documented arguments (GH10888)
  • Bug in indexing of large DataFrame where IndexError is uncaught (GH10645 and GH10692)
  • Bug in read_csv when using the nrows or chunksize parameters if file contains only a header line (GH9535)
  • Bug in serialization of category types in HDF5 in presence of alternate encodings. (GH10366)
  • Bug in pd.DataFrame when constructing an empty DataFrame with a string dtype (GH9428)
  • Bug in pd.DataFrame.diff when DataFrame is not consolidated (GH10907)
  • Bug in pd.unique for arrays with the datetime64 or timedelta64 dtype that meant an array with object dtype was returned instead the original dtype (GH9431)
  • Bug in Timedelta raising error when slicing from 0s (GH10583)
  • Bug in DatetimeIndex.take and TimedeltaIndex.take may not raise IndexError against invalid index (GH10295)
  • Bug in Series([np.nan]).astype('M8[ms]'), which now returns Series([pd.NaT]) (GH10747)
  • Bug in PeriodIndex.order reset freq (GH10295)
  • Bug in date_range when freq divides end as nanos (GH10885)
  • Bug in iloc allowing memory outside bounds of a Series to be accessed with negative integers (GH10779)
  • Bug in read_msgpack where encoding is not respected (GH10581)
  • Bug preventing access to the first index when using iloc with a list containing the appropriate negative integer (GH10547, GH10779)
  • Bug in TimedeltaIndex formatter causing error while trying to save DataFrame with TimedeltaIndex using to_csv (GH10833)
  • Bug in DataFrame.where when handling Series slicing (GH10218, GH9558)
  • Bug where pd.read_gbq throws ValueError when Bigquery returns zero rows (GH10273)
  • Bug in to_json which was causing segmentation fault when serializing 0-rank ndarray (GH9576)
  • Bug in plotting functions may raise IndexError when plotted on GridSpec (GH10819)
  • Bug in plot result may show unnecessary minor ticklabels (GH10657)
  • Bug in groupby incorrect computation for aggregation on DataFrame with NaT (E.g first, last, min). (GH10590, GH11010)
  • Bug when constructing DataFrame where passing a dictionary with only scalar values and specifying columns did not raise an error (GH10856)
  • Bug in .var() causing roundoff errors for highly similar values (GH10242)
  • Bug in DataFrame.plot(subplots=True) with duplicated columns outputs incorrect result (GH10962)
  • Bug in Index arithmetic may result in incorrect class (GH10638)
  • Bug in date_range results in empty if freq is negative annualy, quarterly and monthly (GH11018)
  • Bug in DatetimeIndex cannot infer negative freq (GH11018)
  • Remove use of some deprecated numpy comparison operations, mainly in tests. (GH10569)
  • Bug in Index dtype may not applied properly (GH11017)
  • Bug in io.gbq when testing for minimum google api client version (GH10652)
  • Bug in DataFrame construction from nested dict with timedelta keys (GH11129)
  • Bug in .fillna against may raise TypeError when data contains datetime dtype (GH7095, GH11153)
  • Bug in .groupby when number of keys to group by is same as length of index (GH11185)
  • Bug in convert_objects where converted values might not be returned if all null and coerce (GH9589)
  • Bug in convert_objects where copy keyword was not respected (GH9589)

v0.16.2 (June 12, 2015)

This is a minor bug-fix release from 0.16.1 and includes a a large number of bug fixes along some new features (pipe() method), enhancements, and performance improvements.

We recommend that all users upgrade to this version.

Highlights include:

  • A new pipe method, see here
  • Documentation on how to use numba with pandas, see here

New features


We’ve introduced a new method DataFrame.pipe(). As suggested by the name, pipe should be used to pipe data through a chain of function calls. The goal is to avoid confusing nested function calls like

# df is a DataFrame
# f, g, and h are functions that take and return DataFrames
f(g(h(df), arg1=1), arg2=2, arg3=3)

The logic flows from inside out, and function names are separated from their keyword arguments. This can be rewritten as

   .pipe(g, arg1=1)
   .pipe(f, arg2=2, arg3=3)

Now both the code and the logic flow from top to bottom. Keyword arguments are next to their functions. Overall the code is much more readable.

In the example above, the functions f, g, and h each expected the DataFrame as the first positional argument. When the function you wish to apply takes its data anywhere other than the first argument, pass a tuple of (function, keyword) indicating where the DataFrame should flow. For example:

In [1]: import statsmodels.formula.api as sm

In [2]: bb = pd.read_csv('data/baseball.csv', index_col='id')

# sm.poisson takes (formula, data)
In [3]: (bb.query('h > 0')
   ...:    .assign(ln_h = lambda df: np.log(df.h))
   ...:    .pipe((sm.poisson, 'data'), 'hr ~ ln_h + year + g + C(lg)')
   ...:    .fit()
   ...:    .summary()
   ...: )
Optimization terminated successfully.
         Current function value: 2.116284
         Iterations 24
<class 'statsmodels.iolib.summary.Summary'>
                          Poisson Regression Results                          
Dep. Variable:                     hr   No. Observations:                   68
Model:                        Poisson   Df Residuals:                       63
Method:                           MLE   Df Model:                            4
Date:                Tue, 03 May 2016   Pseudo R-squ.:                  0.6878
Time:                        09:45:10   Log-Likelihood:                -143.91
converged:                       True   LL-Null:                       -460.91
                                        LLR p-value:                6.774e-136
                  coef    std err          z      P>|z|      [95.0% Conf. Int.]
Intercept   -1267.3636    457.867     -2.768      0.006     -2164.767  -369.960
C(lg)[T.NL]    -0.2057      0.101     -2.044      0.041        -0.403    -0.008
ln_h            0.9280      0.191      4.866      0.000         0.554     1.302
year            0.6301      0.228      2.762      0.006         0.183     1.077
g               0.0099      0.004      2.754      0.006         0.003     0.017

The pipe method is inspired by unix pipes, which stream text through processes. More recently dplyr and magrittr have introduced the popular (%>%) pipe operator for R.

See the documentation for more. (GH10129)

Other Enhancements

  • Added rsplit to Index/Series StringMethods (GH10303)

  • Removed the hard-coded size limits on the DataFrame HTML representation in the IPython notebook, and leave this to IPython itself (only for IPython v3.0 or greater). This eliminates the duplicate scroll bars that appeared in the notebook with large frames (GH10231).

    Note that the notebook has a toggle output scrolling feature to limit the display of very large frames (by clicking left of the output). You can also configure the way DataFrames are displayed using the pandas options, see here here.

  • axis parameter of DataFrame.quantile now accepts also index and column. (GH9543)

API Changes

  • Holiday now raises NotImplementedError if both offset and observance are used in the constructor instead of returning an incorrect result (GH10217).

Performance Improvements

  • Improved Series.resample performance with dtype=datetime64[ns] (GH7754)
  • Increase performance of str.split when expand=True (GH10081)

Bug Fixes

  • Bug in Series.hist raises an error when a one row Series was given (GH10214)
  • Bug where modifies the passed columns list (GH7212)
  • Bug in Categorical repr with display.width of None in Python 3 (GH10087)
  • Bug in to_json with certain orients and a CategoricalIndex would segfault (GH10317)
  • Bug where some of the nan funcs do not have consistent return dtypes (GH10251)
  • Bug in DataFrame.quantile on checking that a valid axis was passed (GH9543)
  • Bug in groupby.apply aggregation for Categorical not preserving categories (GH10138)
  • Bug in to_csv where date_format is ignored if the datetime is fractional (GH10209)
  • Bug in DataFrame.to_json with mixed data types (GH10289)
  • Bug in cache updating when consolidating (GH10264)
  • Bug in mean() where integer dtypes can overflow (GH10172)
  • Bug where Panel.from_dict does not set dtype when specified (GH10058)
  • Bug in Index.union raises AttributeError when passing array-likes. (GH10149)
  • Bug in Timestamp‘s’ microsecond, quarter, dayofyear, week and daysinmonth properties return type, not built-in int. (GH10050)
  • Bug in NaT raises AttributeError when accessing to daysinmonth, dayofweek properties. (GH10096)
  • Bug in Index repr when using the max_seq_items=None setting (GH10182).
  • Bug in getting timezone data with dateutil on various platforms ( GH9059, GH8639, GH9663, GH10121)
  • Bug in displaying datetimes with mixed frequencies; display ‘ms’ datetimes to the proper precision. (GH10170)
  • Bug in setitem where type promotion is applied to the entire block (GH10280)
  • Bug in Series arithmetic methods may incorrectly hold names (GH10068)
  • Bug in GroupBy.get_group when grouping on multiple keys, one of which is categorical. (GH10132)
  • Bug in DatetimeIndex and TimedeltaIndex names are lost after timedelta arithmetics ( GH9926)
  • Bug in DataFrame construction from nested dict with datetime64 (GH10160)
  • Bug in Series construction from dict with datetime64 keys (GH9456)
  • Bug in Series.plot(label="LABEL") not correctly setting the label (GH10119)
  • Bug in plot not defaulting to matplotlib axes.grid setting (GH9792)
  • Bug causing strings containing an exponent, but no decimal to be parsed as int instead of float in engine='python' for the read_csv parser (GH9565)
  • Bug in Series.align resets name when fill_value is specified (GH10067)
  • Bug in read_csv causing index name not to be set on an empty DataFrame (GH10184)
  • Bug in SparseSeries.abs resets name (GH10241)
  • Bug in TimedeltaIndex slicing may reset freq (GH10292)
  • Bug in GroupBy.get_group raises ValueError when group key contains NaT (GH6992)
  • Bug in SparseSeries constructor ignores input data name (GH10258)
  • Bug in Categorical.remove_categories causing a ValueError when removing the NaN category if underlying dtype is floating-point (GH10156)
  • Bug where infer_freq infers timerule (WOM-5XXX) unsupported by to_offset (GH9425)
  • Bug in DataFrame.to_hdf() where table format would raise a seemingly unrelated error for invalid (non-string) column names. This is now explicitly forbidden. (GH9057)
  • Bug to handle masking empty DataFrame (GH10126).
  • Bug where MySQL interface could not handle numeric table/column names (GH10255)
  • Bug in read_csv with a date_parser that returned a datetime64 array of other time resolution than [ns] (GH10245)
  • Bug in Panel.apply when the result has ndim=0 (GH10332)
  • Bug in read_hdf where auto_close could not be passed (GH9327).
  • Bug in read_hdf where open stores could not be used (GH10330).
  • Bug in adding empty DataFrame``s, now results in a ``DataFrame that .equals an empty DataFrame (GH10181).
  • Bug in to_hdf and HDFStore which did not check that complib choices were valid (GH4582, GH8874).

v0.16.1 (May 11, 2015)

This is a minor bug-fix release from 0.16.0 and includes a a large number of bug fixes along several new features, enhancements, and performance improvements. We recommend that all users upgrade to this version.

Highlights include:

  • Support for a CategoricalIndex, a category based index, see here
  • New section on how-to-contribute to pandas, see here
  • Revised “Merge, join, and concatenate” documentation, including graphical examples to make it easier to understand each operations, see here
  • New method sample for drawing random samples from Series, DataFrames and Panels. See here
  • The default Index printing has changed to a more uniform format, see here
  • BusinessHour datetime-offset is now supported, see here
  • Further enhancement to the .str accessor to make string operations easier, see here


In pandas 0.17.0, the sub-package will be removed in favor of a separately installable package. See here for details (GH8961)



We introduce a CategoricalIndex, a new type of index object that is useful for supporting indexing with duplicates. This is a container around a Categorical (introduced in v0.15.0) and allows efficient indexing and storage of an index with a large number of duplicated elements. Prior to 0.16.1, setting the index of a DataFrame/Series with a category dtype would convert this to regular object-based Index.

In [1]: df = DataFrame({'A' : np.arange(6),
   ...:                 'B' : Series(list('aabbca')).astype('category',
   ...:                                                     categories=list('cab'))
   ...:                })

In [2]: df
   A  B
0  0  a
1  1  a
2  2  b
3  3  b
4  4  c
5  5  a

In [3]: df.dtypes
A       int64
B    category
dtype: object

In [4]:
Out[4]: Index([u'c', u'a', u'b'], dtype='object')

setting the index, will create create a CategoricalIndex

In [5]: df2 = df.set_index('B')

In [6]: df2.index
Out[6]: CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'], categories=[u'c', u'a', u'b'], ordered=False, name=u'B', dtype='category')

indexing with __getitem__/.iloc/.loc/.ix works similarly to an Index with duplicates. The indexers MUST be in the category or the operation will raise.

In [7]: df2.loc['a']
a  0
a  1
a  5

and preserves the CategoricalIndex

In [8]: df2.loc['a'].index
Out[8]: CategoricalIndex([u'a', u'a', u'a'], categories=[u'c', u'a', u'b'], ordered=False, name=u'B', dtype='category')

sorting will order by the order of the categories

In [9]: df2.sort_index()
c  4
a  0
a  1
a  5
b  2
b  3

groupby operations on the index will preserve the index nature as well

In [10]: df2.groupby(level=0).sum()
c  4
a  6
b  5

In [11]: df2.groupby(level=0).sum().index
Out[11]: CategoricalIndex([u'c', u'a', u'b'], categories=[u'c', u'a', u'b'], ordered=False, name=u'B', dtype='category')

reindexing operations, will return a resulting index based on the type of the passed indexer, meaning that passing a list will return a plain-old-Index; indexing with a Categorical will return a CategoricalIndex, indexed according to the categories of the PASSED Categorical dtype. This allows one to arbitrarly index these even with values NOT in the categories, similarly to how you can reindex ANY pandas index.

In [12]: df2.reindex(['a','e'])
a  0.0
a  1.0
a  5.0
e  NaN

In [13]: df2.reindex(['a','e']).index
Out[13]: Index([u'a', u'a', u'a', u'e'], dtype='object', name=u'B')

In [14]: df2.reindex(pd.Categorical(['a','e'],categories=list('abcde')))
a  0.0
a  1.0
a  5.0
e  NaN

In [15]: df2.reindex(pd.Categorical(['a','e'],categories=list('abcde'))).index
Out[15]: CategoricalIndex([u'a', u'a', u'a', u'e'], categories=[u'a', u'b', u'c', u'd', u'e'], ordered=False, name=u'B', dtype='category')

See the documentation for more. (GH7629, GH10038, GH10039)


Series, DataFrames, and Panels now have a new method: sample(). The method accepts a specific number of rows or columns to return, or a fraction of the total number or rows or columns. It also has options for sampling with or without replacement, for passing in a column for weights for non-uniform sampling, and for setting seed values to facilitate replication. (GH2419)

In [16]: example_series = Series([0,1,2,3,4,5])

# When no arguments are passed, returns 1
In [17]: example_series.sample()
4    4
dtype: int64

# One may specify either a number of rows:
In [18]: example_series.sample(n=3)
4    4
2    2
3    3
dtype: int64

# Or a fraction of the rows:
In [19]: example_series.sample(frac=0.5)
4    4
3    3
5    5
dtype: int64

# weights are accepted.
In [20]: example_weights = [0, 0, 0.2, 0.2, 0.2, 0.4]

In [21]: example_series.sample(n=3, weights=example_weights)
2    2
5    5
3    3
dtype: int64

# weights will also be normalized if they do not sum to one,
# and missing values will be treated as zeros.
In [22]: example_weights2 = [0.5, 0, 0, 0, None, np.nan]

In [23]: example_series.sample(n=1, weights=example_weights2)
0    0
dtype: int64

When applied to a DataFrame, one may pass the name of a column to specify sampling weights when sampling from rows.

In [24]: df = DataFrame({'col1':[9,8,7,6], 'weight_column':[0.5, 0.4, 0.1, 0]})

In [25]: df.sample(n=3, weights='weight_column')
   col1  weight_column
0     9            0.5
1     8            0.4
2     7            0.1

String Methods Enhancements

Continuing from v0.16.0, the following enhancements make string operations easier and more consistent with standard python string operations.

  • Added StringMethods (.str accessor) to Index (GH9068)

    The .str accessor is now available for both Series and Index.

    In [26]: idx = Index([' jack', 'jill ', ' jesse ', 'frank'])
    In [27]: idx.str.strip()
    Out[27]: Index([u'jack', u'jill', u'jesse', u'frank'], dtype='object')

    One special case for the .str accessor on Index is that if a string method returns bool, the .str accessor will return a np.array instead of a boolean Index (GH8875). This enables the following expression to work naturally:

    In [28]: idx = Index(['a1', 'a2', 'b1', 'b2'])
    In [29]: s = Series(range(4), index=idx)
    In [30]: s
    a1    0
    a2    1
    b1    2
    b2    3
    dtype: int64
    In [31]: idx.str.startswith('a')
    Out[31]: array([ True,  True, False, False], dtype=bool)
    In [32]: s[s.index.str.startswith('a')]
    a1    0
    a2    1
    dtype: int64
  • The following new methods are accesible via .str accessor to apply the function to each values. (GH9766, GH9773, GH10031, GH10045, GH10052)

    capitalize() swapcase() normalize() partition() rpartition()
    index() rindex() translate()    
  • split now takes expand keyword to specify whether to expand dimensionality. return_type is deprecated. (GH9847)

    In [33]: s = Series(['a,b', 'a,c', 'b,c'])
    # return Series
    In [34]: s.str.split(',')
    0    [a, b]
    1    [a, c]
    2    [b, c]
    dtype: object
    # return DataFrame
    In [35]: s.str.split(',', expand=True)
       0  1
    0  a  b
    1  a  c
    2  b  c
    In [36]: idx = Index(['a,b', 'a,c', 'b,c'])
    # return Index
    In [37]: idx.str.split(',')
    Out[37]: Index([[u'a', u'b'], [u'a', u'c'], [u'b', u'c']], dtype='object')
    # return MultiIndex
    In [38]: idx.str.split(',', expand=True)
    MultiIndex(levels=[[u'a', u'b'], [u'b', u'c']],
               labels=[[0, 0, 1], [0, 1, 1]])
  • Improved extract and get_dummies methods for Index.str (GH9980)

Other Enhancements

  • BusinessHour offset is now supported, which represents business hours starting from 09:00 - 17:00 on BusinessDay by default. See Here for details. (GH7905)

    In [39]: from pandas.tseries.offsets import BusinessHour
    In [40]: Timestamp('2014-08-01 09:00') + BusinessHour()
    Out[40]: Timestamp('2014-08-01 10:00:00')
    In [41]: Timestamp('2014-08-01 07:00') + BusinessHour()
    Out[41]: Timestamp('2014-08-01 10:00:00')
    In [42]: Timestamp('2014-08-01 16:30') + BusinessHour()
    Out[42]: Timestamp('2014-08-04 09:30:00')
  • DataFrame.diff now takes an axis parameter that determines the direction of differencing (GH9727)

  • Allow clip, clip_lower, and clip_upper to accept array-like arguments as thresholds (This is a regression from 0.11.0). These methods now have an axis parameter which determines how the Series or DataFrame will be aligned with the threshold(s). (GH6966)

  • DataFrame.mask() and Series.mask() now support same keywords as where (GH8801)

  • drop function can now accept errors keyword to suppress ValueError raised when any of label does not exist in the target data. (GH6736)

    In [43]: df = DataFrame(np.random.randn(3, 3), columns=['A', 'B', 'C'])
    In [44]: df.drop(['A', 'X'], axis=1, errors='ignore')
              B         C
    0  0.991946  0.953324
    1 -0.334077  0.002118
    2  0.289092  1.321158
  • Add support for separating years and quarters using dashes, for example 2014-Q1. (GH9688)

  • Allow conversion of values with dtype datetime64 or timedelta64 to strings using astype(str) (GH9757)

  • get_dummies function now accepts sparse keyword. If set to True, the return DataFrame is sparse, e.g. SparseDataFrame. (GH8823)

  • Period now accepts datetime64 as value input. (GH9054)

  • Allow timedelta string conversion when leading zero is missing from time definition, ie 0:00:00 vs 00:00:00. (GH9570)

  • Allow Panel.shift with axis='items' (GH9890)

  • Trying to write an excel file now raises NotImplementedError if the DataFrame has a MultiIndex instead of writing a broken Excel file. (GH9794)

  • Allow Categorical.add_categories to accept Series or np.array. (GH9927)

  • Add/delete str/dt/cat accessors dynamically from __dir__. (GH9910)

  • Add normalize as a dt accessor method. (GH10047)

  • DataFrame and Series now have _constructor_expanddim property as overridable constructor for one higher dimensionality data. This should be used only when it is really needed, see here

  • pd.lib.infer_dtype now returns 'bytes' in Python 3 where appropriate. (GH10032)

API changes

  • When passing in an ax to df.plot( ..., ax=ax), the sharex kwarg will now default to False. The result is that the visibility of xlabels and xticklabels will not anymore be changed. You have to do that by yourself for the right axes in your figure or set sharex=True explicitly (but this changes the visible for all axes in the figure, not only the one which is passed in!). If pandas creates the subplots itself (e.g. no passed in ax kwarg), then the default is still sharex=True and the visibility changes are applied.
  • assign() now inserts new columns in alphabetical order. Previously the order was arbitrary. (GH9777)
  • By default, read_csv and read_table will now try to infer the compression type based on the file extension. Set compression=None to restore the previous behavior (no decompression). (GH9770)


  • Series.str.split‘s return_type keyword was removed in favor of expand (GH9847)

Index Representation

The string representation of Index and its sub-classes have now been unified. These will show a single-line display if there are few values; a wrapped multi-line display for a lot of values (but less than display.max_seq_items; if lots of items (> display.max_seq_items) will show a truncated display (the head and tail of the data). The formatting for MultiIndex is unchanges (a multi-line wrapped display). The display width responds to the option display.max_seq_items, which is defaulted to 100. (GH6482)

Previous Behavior

In [2]: pd.Index(range(4),name='foo')
Out[2]: Int64Index([0, 1, 2, 3], dtype='int64')

In [3]: pd.Index(range(104),name='foo')
Out[3]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, ...], dtype='int64')

In [4]: pd.date_range('20130101',periods=4,name='foo',tz='US/Eastern')
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00-05:00, ..., 2013-01-04 00:00:00-05:00]
Length: 4, Freq: D, Timezone: US/Eastern

In [5]: pd.date_range('20130101',periods=104,name='foo',tz='US/Eastern')
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00-05:00, ..., 2013-04-14 00:00:00-04:00]
Length: 104, Freq: D, Timezone: US/Eastern

New Behavior

In [45]: pd.set_option('display.width', 80)

In [46]: pd.Index(range(4), name='foo')
Out[46]: Int64Index([0, 1, 2, 3], dtype='int64', name=u'foo')

In [47]: pd.Index(range(30), name='foo')
Int64Index([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
            17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
           dtype='int64', name=u'foo')

In [48]: pd.Index(range(104), name='foo')
Int64Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
             94,  95,  96,  97,  98,  99, 100, 101, 102, 103],
           dtype='int64', name=u'foo', length=104)

In [49]: pd.CategoricalIndex(['a','bb','ccc','dddd'], ordered=True, name='foobar')
Out[49]: CategoricalIndex([u'a', u'bb', u'ccc', u'dddd'], categories=[u'a', u'bb', u'ccc', u'dddd'], ordered=True, name=u'foobar', dtype='category')

In [50]: pd.CategoricalIndex(['a','bb','ccc','dddd']*10, ordered=True, name='foobar')
CategoricalIndex([u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd',
                  u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd',
                  u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd',
                  u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd',
                  u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd'],
                 categories=[u'a', u'bb', u'ccc', u'dddd'], ordered=True, name=u'foobar', dtype='category')

In [51]: pd.CategoricalIndex(['a','bb','ccc','dddd']*100, ordered=True, name='foobar')
CategoricalIndex([u'a', u'bb', u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd',
                  u'a', u'bb',
                  u'ccc', u'dddd', u'a', u'bb', u'ccc', u'dddd', u'a', u'bb',
                  u'ccc', u'dddd'],
                 categories=[u'a', u'bb', u'ccc', u'dddd'], ordered=True, name=u'foobar', dtype='category', length=400)

In [52]: pd.date_range('20130101',periods=4, name='foo', tz='US/Eastern')
DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
               '2013-01-03 00:00:00-05:00', '2013-01-04 00:00:00-05:00'],
              dtype='datetime64[ns, US/Eastern]', name=u'foo', freq='D')

In [53]: pd.date_range('20130101',periods=25, freq='D')
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
               '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08',
               '2013-01-09', '2013-01-10', '2013-01-11', '2013-01-12',
               '2013-01-13', '2013-01-14', '2013-01-15', '2013-01-16',
               '2013-01-17', '2013-01-18', '2013-01-19', '2013-01-20',
               '2013-01-21', '2013-01-22', '2013-01-23', '2013-01-24',
              dtype='datetime64[ns]', freq='D')

In [54]: pd.date_range('20130101',periods=104, name='foo', tz='US/Eastern')
DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
               '2013-01-03 00:00:00-05:00', '2013-01-04 00:00:00-05:00',
               '2013-01-05 00:00:00-05:00', '2013-01-06 00:00:00-05:00',
               '2013-01-07 00:00:00-05:00', '2013-01-08 00:00:00-05:00',
               '2013-01-09 00:00:00-05:00', '2013-01-10 00:00:00-05:00',
               '2013-04-05 00:00:00-04:00', '2013-04-06 00:00:00-04:00',
               '2013-04-07 00:00:00-04:00', '2013-04-08 00:00:00-04:00',
               '2013-04-09 00:00:00-04:00', '2013-04-10 00:00:00-04:00',
               '2013-04-11 00:00:00-04:00', '2013-04-12 00:00:00-04:00',
               '2013-04-13 00:00:00-04:00', '2013-04-14 00:00:00-04:00'],
              dtype='datetime64[ns, US/Eastern]', name=u'foo', length=104, freq='D')

Performance Improvements

  • Improved csv write performance with mixed dtypes, including datetimes by up to 5x (GH9940)
  • Improved csv write performance generally by 2x (GH9940)
  • Improved the performance of pd.lib.max_len_string_array by 5-7x (GH10024)

Bug Fixes

  • Bug where labels did not appear properly in the legend of DataFrame.plot(), passing label= arguments works, and Series indices are no longer mutated. (GH9542)
  • Bug in json serialization causing a segfault when a frame had zero length. (GH9805)
  • Bug in read_csv where missing trailing delimiters would cause segfault. (GH5664)
  • Bug in retaining index name on appending (GH9862)
  • Bug in scatter_matrix draws unexpected axis ticklabels (GH5662)
  • Fixed bug in StataWriter resulting in changes to input DataFrame upon save (GH9795).
  • Bug in transform causing length mismatch when null entries were present and a fast aggregator was being used (GH9697)
  • Bug in equals causing false negatives when block order differed (GH9330)
  • Bug in grouping with multiple pd.Grouper where one is non-time based (GH10063)
  • Bug in read_sql_table error when reading postgres table with timezone (GH7139)
  • Bug in DataFrame slicing may not retain metadata (GH9776)
  • Bug where TimdeltaIndex were not properly serialized in fixed HDFStore (GH9635)
  • Bug with TimedeltaIndex constructor ignoring name when given another TimedeltaIndex as data (GH10025).
  • Bug in DataFrameFormatter._get_formatted_index with not applying max_colwidth to the DataFrame index (GH7856)
  • Bug in .loc with a read-only ndarray data source (GH10043)
  • Bug in groupby.apply() that would raise if a passed user defined function either returned only None (for all input). (GH9685)
  • Always use temporary files in pytables tests (GH9992)
  • Bug in plotting continuously using secondary_y may not show legend properly. (GH9610, GH9779)
  • Bug in DataFrame.plot(kind="hist") results in TypeError when DataFrame contains non-numeric columns (GH9853)
  • Bug where repeated plotting of DataFrame with a DatetimeIndex may raise TypeError (GH9852)
  • Bug in that would allow an incompat cython version to build (GH9827)
  • Bug in plotting secondary_y incorrectly attaches right_ax property to secondary axes specifying itself recursively. (GH9861)
  • Bug in Series.quantile on empty Series of type Datetime or Timedelta (GH9675)
  • Bug in where causing incorrect results when upcasting was required (GH9731)
  • Bug in FloatArrayFormatter where decision boundary for displaying “small” floats in decimal format is off by one order of magnitude for a given display.precision (GH9764)
  • Fixed bug where DataFrame.plot() raised an error when both color and style keywords were passed and there was no color symbol in the style strings (GH9671)
  • Not showing a DeprecationWarning on combining list-likes with an Index (GH10083)
  • Bug in read_csv and read_table when using skip_rows parameter if blank lines are present. (GH9832)
  • Bug in read_csv() interprets index_col=True as 1 (GH9798)
  • Bug in index equality comparisons using == failing on Index/MultiIndex type incompatibility (GH9785)
  • Bug in which SparseDataFrame could not take nan as a column name (GH8822)
  • Bug in to_msgpack and read_msgpack zlib and blosc compression support (GH9783)
  • Bug GroupBy.size doesn’t attach index name properly if grouped by TimeGrouper (GH9925)
  • Bug causing an exception in slice assignments because length_of_indexer returns wrong results (GH9995)
  • Bug in csv parser causing lines with initial whitespace plus one non-space character to be skipped. (GH9710)
  • Bug in C csv parser causing spurious NaNs when data started with newline followed by whitespace. (GH10022)
  • Bug causing elements with a null group to spill into the final group when grouping by a Categorical (GH9603)
  • Bug where .iloc and .loc behavior is not consistent on empty dataframes (GH9964)
  • Bug in invalid attribute access on a TimedeltaIndex incorrectly raised ValueError instead of AttributeError (GH9680)
  • Bug in unequal comparisons between categorical data and a scalar, which was not in the categories (e.g. Series(Categorical(list("abc"), ordered=True)) > "d". This returned False for all elements, but now raises a TypeError. Equality comparisons also now return False for == and True for !=. (GH9848)
  • Bug in DataFrame __setitem__ when right hand side is a dictionary (GH9874)
  • Bug in where when dtype is datetime64/timedelta64, but dtype of other is not (GH9804)
  • Bug in MultiIndex.sortlevel() results in unicode level name breaks (GH9856)
  • Bug in which groupby.transform incorrectly enforced output dtypes to match input dtypes. (GH9807)
  • Bug in DataFrame constructor when columns parameter is set, and data is an empty list (GH9939)
  • Bug in bar plot with log=True raises TypeError if all values are less than 1 (GH9905)
  • Bug in horizontal bar plot ignores log=True (GH9905)
  • Bug in PyTables queries that did not return proper results using the index (GH8265, GH9676)
  • Bug where dividing a dataframe containing values of type Decimal by another Decimal would raise. (GH9787)
  • Bug where using DataFrames asfreq would remove the name of the index. (GH9885)
  • Bug causing extra index point when resample BM/BQ (GH9756)
  • Changed caching in AbstractHolidayCalendar to be at the instance level rather than at the class level as the latter can result in unexpected behaviour. (GH9552)
  • Fixed latex output for multi-indexed dataframes (GH9778)
  • Bug causing an exception when setting an empty range using DataFrame.loc (GH9596)
  • Bug in hiding ticklabels with subplots and shared axes when adding a new plot to an existing grid of axes (GH9158)
  • Bug in transform and filter when grouping on a categorical variable (GH9921)
  • Bug in transform when groups are equal in number and dtype to the input index (GH9700)
  • Google BigQuery connector now imports dependencies on a per-method basis.(GH9713)
  • Updated BigQuery connector to no longer use deprecated (GH8327)
  • Bug in subclassed DataFrame. It may not return the correct class, when slicing or subsetting it. (GH9632)
  • Bug in .median() where non-float null values are not handled correctly (GH10040)
  • Bug in Series.fillna() where it raises if a numerically convertible string is given (GH10092)

v0.16.0 (March 22, 2015)

This is a major release from 0.15.2 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all users upgrade to this version.

Highlights include:

  • DataFrame.assign method, see here
  • Series.to_coo/from_coo methods to interact with scipy.sparse, see here
  • Backwards incompatible change to Timedelta to conform the .seconds attribute with datetime.timedelta, see here
  • Changes to the .loc slicing API to conform with the behavior of .ix see here
  • Changes to the default for ordering in the Categorical constructor, see here
  • Enhancement to the .str accessor to make string operations easier, see here
  • The, pandas.sandbox.qtpandas and pandas.rpy modules are deprecated. We refer users to external packages like seaborn, pandas-qt and rpy2 for similar or equivalent functionality, see here

Check the API Changes and deprecations before updating.

New features

DataFrame Assign

Inspired by dplyr’s mutate verb, DataFrame has a new assign() method. The function signature for assign is simply **kwargs. The keys are the column names for the new fields, and the values are either a value to be inserted (for example, a Series or NumPy array), or a function of one argument to be called on the DataFrame. The new values are inserted, and the entire DataFrame (with all original and new columns) is returned.

In [1]: iris = read_csv('data/')

In [2]: iris.head()
   SepalLength  SepalWidth  PetalLength  PetalWidth         Name
0          5.1         3.5          1.4         0.2  Iris-setosa
1          4.9         3.0          1.4         0.2  Iris-setosa
2          4.7         3.2          1.3         0.2  Iris-setosa
3          4.6         3.1          1.5         0.2  Iris-setosa
4          5.0         3.6          1.4         0.2  Iris-setosa

In [3]: iris.assign(sepal_ratio=iris['SepalWidth'] / iris['SepalLength']).head()
   SepalLength  SepalWidth  PetalLength  PetalWidth         Name  sepal_ratio
0          5.1         3.5          1.4         0.2  Iris-setosa     0.686275
1          4.9         3.0          1.4         0.2  Iris-setosa     0.612245
2          4.7         3.2          1.3         0.2  Iris-setosa     0.680851
3          4.6         3.1          1.5         0.2  Iris-setosa     0.673913
4          5.0         3.6          1.4         0.2  Iris-setosa     0.720000

Above was an example of inserting a precomputed value. We can also pass in a function to be evalutated.

In [4]: iris.assign(sepal_ratio = lambda x: (x['SepalWidth'] /
   ...:                                      x['SepalLength'])).head()
   SepalLength  SepalWidth  PetalLength  PetalWidth         Name  sepal_ratio
0          5.1         3.5          1.4         0.2  Iris-setosa     0.686275
1          4.9         3.0          1.4         0.2  Iris-setosa     0.612245
2          4.7         3.2          1.3         0.2  Iris-setosa     0.680851
3          4.6         3.1          1.5         0.2  Iris-setosa     0.673913
4          5.0         3.6          1.4         0.2  Iris-setosa     0.720000

The power of assign comes when used in chains of operations. For example, we can limit the DataFrame to just those with a Sepal Length greater than 5, calculate the ratio, and plot

In [5]: (iris.query('SepalLength > 5')
   ...:      .assign(SepalRatio = lambda x: x.SepalWidth / x.SepalLength,
   ...:              PetalRatio = lambda x: x.PetalWidth / x.PetalLength)
   ...:      .plot(kind='scatter', x='SepalRatio', y='PetalRatio'))
Out[5]: <matplotlib.axes._subplots.AxesSubplot at 0x134090390>

See the documentation for more. (GH9229)

Interaction with scipy.sparse

Added SparseSeries.to_coo() and SparseSeries.from_coo() methods (GH8048) for converting to and from scipy.sparse.coo_matrix instances (see here). For example, given a SparseSeries with MultiIndex we can convert to a scipy.sparse.coo_matrix by specifying the row and column labels as index levels:

In [6]: from numpy import nan

In [7]: s = Series([3.0, nan, 1.0, 3.0, nan, nan])

In [8]: s.index = MultiIndex.from_tuples([(1, 2, 'a', 0),
   ...:                                   (1, 2, 'a', 1),
   ...:                                   (1, 1, 'b', 0),
   ...:                                   (1, 1, 'b', 1),
   ...:                                   (2, 1, 'b', 0),
   ...:                                   (2, 1, 'b', 1)],
   ...:                                   names=['A', 'B', 'C', 'D'])

In [9]: s
A  B  C  D
1  2  a  0    3.0
         1    NaN
   1  b  0    1.0
         1    3.0
2  1  b  0    NaN
         1    NaN
dtype: float64

# SparseSeries
In [10]: ss = s.to_sparse()

In [11]: ss
A  B  C  D
1  2  a  0    3.0
         1    NaN
   1  b  0    1.0
         1    3.0
2  1  b  0    NaN
         1    NaN
dtype: float64
Block locations: array([0, 2], dtype=int32)
Block lengths: array([1, 2], dtype=int32)

In [12]: A, rows, columns = ss.to_coo(row_levels=['A', 'B'],
   ....:                              column_levels=['C', 'D'],
   ....:                              sort_labels=False)

In [13]: A
<3x4 sparse matrix of type '<type 'numpy.float64'>'
	with 3 stored elements in COOrdinate format>

In [14]: A.todense()
matrix([[ 3.,  0.,  0.,  0.],
        [ 0.,  0.,  1.,  3.],
        [ 0.,  0.,  0.,  0.]])

In [15]: rows
Out[15]: [(1, 2), (1, 1), (2, 1)]

In [16]: columns
Out[16]: [('a', 0), ('a', 1), ('b', 0), ('b', 1)]

The from_coo method is a convenience method for creating a SparseSeries from a scipy.sparse.coo_matrix:

In [17]: from scipy import sparse

In [18]: A = sparse.coo_matrix(([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])),
   ....:                             shape=(3, 4))

In [19]: A
<3x4 sparse matrix of type '<type 'numpy.float64'>'
	with 3 stored elements in COOrdinate format>

In [20]: A.todense()
matrix([[ 0.,  0.,  1.,  2.],
        [ 3.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.]])

In [21]: ss = SparseSeries.from_coo(A)

In [22]: ss
0  2    1.0
   3    2.0
1  0    3.0
dtype: float64
Block locations: array([0], dtype=int32)
Block lengths: array([3], dtype=int32)

String Methods Enhancements

  • Following new methods are accesible via .str accessor to apply the function to each values. This is intended to make it more consistent with standard methods on strings. (GH9282, GH9352, GH9386, GH9387, GH9439)

    isalnum() isalpha() isdigit() isdigit() isspace()
    islower() isupper() istitle() isnumeric() isdecimal()
    find() rfind() ljust() rjust() zfill()
    In [23]: s = Series(['abcd', '3456', 'EFGH'])
    In [24]: s.str.isalpha()
    0     True
    1    False
    2     True
    dtype: bool
    In [25]: s.str.find('ab')
    0    0
    1   -1
    2   -1
    dtype: int64
  • Series.str.pad() and now accept fillchar option to specify filling character (GH9352)

    In [26]: s = Series(['12', '300', '25'])
    In [27]: s.str.pad(5, fillchar='_')
    0    ___12
    1    __300
    2    ___25
    dtype: object
  • Added Series.str.slice_replace(), which previously raised NotImplementedError (GH8888)

    In [28]: s = Series(['ABCD', 'EFGH', 'IJK'])
    In [29]: s.str.slice_replace(1, 3, 'X')
    0    AXD
    1    EXH
    2     IX
    dtype: object
    # replaced with empty char
    In [30]: s.str.slice_replace(0, 1)
    0    BCD
    1    FGH
    2     JK
    dtype: object

Other enhancements

  • Reindex now supports method='nearest' for frames or series with a monotonic increasing or decreasing index (GH9258):

    In [31]: df = pd.DataFrame({'x': range(5)})
    In [32]: df.reindex([0.2, 1.8, 3.5], method='nearest')
    0.2  0
    1.8  2
    3.5  4

    This method is also exposed by the lower level Index.get_indexer and Index.get_loc methods.

  • The read_excel() function’s sheetname argument now accepts a list and None, to get multiple or all sheets respectively. If more than one sheet is specified, a dictionary is returned. (GH9450)

    # Returns the 1st and 4th sheet, as a dictionary of DataFrames.
  • Allow Stata files to be read incrementally with an iterator; support for long strings in Stata files. See the docs here (GH9493:).

  • Paths beginning with ~ will now be expanded to begin with the user’s home directory (GH9066)

  • Added time interval selection in get_data_yahoo (GH9071)

  • Added Timestamp.to_datetime64() to complement Timedelta.to_timedelta64() (GH9255)

  • tseries.frequencies.to_offset() now accepts Timedelta as input (GH9064)

  • Lag parameter was added to the autocorrelation method of Series, defaults to lag-1 autocorrelation (GH9192)

  • Timedelta will now accept nanoseconds keyword in constructor (GH9273)

  • SQL code now safely escapes table and column names (GH8986)

  • Added auto-complete for Series.str.<tab>, Series.dt.<tab> and<tab> (GH9322)

  • Index.get_indexer now supports method='pad' and method='backfill' even for any target array, not just monotonic targets. These methods also work for monotonic decreasing as well as monotonic increasing indexes (GH9258).

  • Index.asof now works on all index types (GH9258).

  • A verbose argument has been augmented in io.read_excel(), defaults to False. Set to True to print sheet names as they are parsed. (GH9450)

  • Added days_in_month (compatibility alias daysinmonth) property to Timestamp, DatetimeIndex, Period, PeriodIndex, and Series.dt (GH9572)

  • Added decimal option in to_csv to provide formatting for non-‘.’ decimal separators (GH781)

  • Added normalize option for Timestamp to normalized to midnight (GH8794)

  • Added example for DataFrame import to R using HDF5 file and rhdf5 library. See the documentation for more (GH9636).

Backwards incompatible API changes

Changes in Timedelta

In v0.15.0 a new scalar type Timedelta was introduced, that is a sub-class of datetime.timedelta. Mentioned here was a notice of an API change w.r.t. the .seconds accessor. The intent was to provide a user-friendly set of accessors that give the ‘natural’ value for that unit, e.g. if you had a Timedelta('1 day, 10:11:12'), then .seconds would return 12. However, this is at odds with the definition of datetime.timedelta, which defines .seconds as 10 * 3600 + 11 * 60 + 12 == 36672.

So in v0.16.0, we are restoring the API to match that of datetime.timedelta. Further, the component values are still available through the .components accessor. This affects the .seconds and .microseconds accessors, and removes the .hours, .minutes, .milliseconds accessors. These changes affect TimedeltaIndex and the Series .dt accessor as well. (GH9185, GH9139)

Previous Behavior

In [2]: t = pd.Timedelta('1 day, 10:11:12.100123')

In [3]: t.days
Out[3]: 1

In [4]: t.seconds
Out[4]: 12

In [5]: t.microseconds
Out[5]: 123

New Behavior

In [33]: t = pd.Timedelta('1 day, 10:11:12.100123')

In [34]: t.days
Out[34]: 1

In [35]: t.seconds
Out[35]: 36672

In [36]: t.microseconds
Out[36]: 100123

Using .components allows the full component access

In [37]: t.components
Out[37]: Components(days=1, hours=10, minutes=11, seconds=12, milliseconds=100, microseconds=123, nanoseconds=0)

In [38]: t.components.seconds
Out[38]: 12

Indexing Changes

The behavior of a small sub-set of edge cases for using .loc have changed (GH8613). Furthermore we have improved the content of the error messages that are raised:

  • Slicing with .loc where the start and/or stop bound is not found in the index is now allowed; this previously would raise a KeyError. This makes the behavior the same as .ix in this case. This change is only for slicing, not when indexing with a single label.

    In [39]: df = DataFrame(np.random.randn(5,4),
       ....:                columns=list('ABCD'),
       ....:                index=date_range('20130101',periods=5))
    In [40]: df
                       A         B         C         D
    2013-01-01 -1.546906 -0.202646 -0.655969  0.193421
    2013-01-02  0.553439  1.318152 -0.469305  0.675554
    2013-01-03 -1.817027 -0.183109  1.058969 -0.397840
    2013-01-04  0.337438  1.047579  1.045938  0.863717
    2013-01-05 -0.122092  0.124713 -0.322795  0.841675
    In [41]: s = Series(range(5),[-2,-1,1,2,3])
    In [42]: s
    -2    0
    -1    1
     1    2
     2    3
     3    4
    dtype: int64

    Previous Behavior

    In [4]: df.loc['2013-01-02':'2013-01-10']
    KeyError: 'stop bound [2013-01-10] is not in the [index]'
    In [6]: s.loc[-10:3]
    KeyError: 'start bound [-10] is not the [index]'

    New Behavior

    In [43]: df.loc['2013-01-02':'2013-01-10']
                       A         B         C         D
    2013-01-02  0.553439  1.318152 -0.469305  0.675554
    2013-01-03 -1.817027 -0.183109  1.058969 -0.397840
    2013-01-04  0.337438  1.047579  1.045938  0.863717
    2013-01-05 -0.122092  0.124713 -0.322795  0.841675
    In [44]: s.loc[-10:3]
    -2    0
    -1    1
     1    2
     2    3
     3    4
    dtype: int64
  • Allow slicing with float-like values on an integer index for .ix. Previously this was only enabled for .loc:

    Previous Behavior

    In [8]: s.ix[-1.0:2]
    TypeError: the slice start value [-1.0] is not a proper indexer for this index type (Int64Index)

    New Behavior

    In [45]: s.ix[-1.0:2]
    -1    1
     1    2
     2    3
    dtype: int64
  • Provide a useful exception for indexing with an invalid type for that index when using .loc. For example trying to use .loc on an index of type DatetimeIndex or PeriodIndex or TimedeltaIndex, with an integer (or a float).

    Previous Behavior

    In [4]: df.loc[2:3]
    KeyError: 'start bound [2] is not the [index]'

    New Behavior

    In [4]: df.loc[2:3]
    TypeError: Cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with <type 'int'> keys

Categorical Changes

In prior versions, Categoricals that had an unspecified ordering (meaning no ordered keyword was passed) were defaulted as ordered Categoricals. Going forward, the ordered keyword in the Categorical constructor will default to False. Ordering must now be explicit.

Furthermore, previously you could change the ordered attribute of a Categorical by just setting the attribute, e.g. cat.ordered=True; This is now deprecated and you should use cat.as_ordered() or cat.as_unordered(). These will by default return a new object and not modify the existing object. (GH9347, GH9190)

Previous Behavior

In [3]: s = Series([0,1,2], dtype='category')

In [4]: s
0    0
1    1
2    2
dtype: category
Categories (3, int64): [0 < 1 < 2]

In [5]:
Out[5]: True

In [6]: = False

In [7]: s
0    0
1    1
2    2
dtype: category
Categories (3, int64): [0, 1, 2]

New Behavior

In [46]: s = Series([0,1,2], dtype='category')

In [47]: s
0    0
1    1
2    2
dtype: category
Categories (3, int64): [0, 1, 2]

In [48]:
Out[48]: False

In [49]: s =

In [50]: s
0    0
1    1
2    2
dtype: category
Categories (3, int64): [0 < 1 < 2]

In [51]:
Out[51]: True

# you can set in the constructor of the Categorical
In [52]: s = Series(Categorical([0,1,2],ordered=True))

In [53]: s
0    0
1    1
2    2
dtype: category
Categories (3, int64): [0 < 1 < 2]

In [54]:
Out[54]: True

For ease of creation of series of categorical data, we have added the ability to pass keywords when calling .astype(). These are passed directly to the constructor.

In [55]: s = Series(["a","b","c","a"]).astype('category',ordered=True)

In [56]: s
0    a
1    b
2    c
3    a
dtype: category
Categories (3, object): [a < b < c]

In [57]: s = Series(["a","b","c","a"]).astype('category',categories=list('abcdef'),ordered=False)

In [58]: s
0    a
1    b
2    c
3    a
dtype: category
Categories (6, object): [a, b, c, d, e, f]

Other API Changes

  • Index.duplicated now returns np.array(dtype=bool) rather than Index(dtype=object) containing bool values. (GH8875)

  • DataFrame.to_json now returns accurate type serialisation for each column for frames of mixed dtype (GH9037)

    Previously data was coerced to a common dtype before serialisation, which for example resulted in integers being serialised to floats:

    In [2]: pd.DataFrame({'i': [1,2], 'f': [3.0, 4.2]}).to_json()
    Out[2]: '{"f":{"0":3.0,"1":4.2},"i":{"0":1.0,"1":2.0}}'

    Now each column is serialised using its correct dtype:

    In [2]:  pd.DataFrame({'i': [1,2], 'f': [3.0, 4.2]}).to_json()
    Out[2]: '{"f":{"0":3.0,"1":4.2},"i":{"0":1,"1":2}}'
  • DatetimeIndex, PeriodIndex and TimedeltaIndex.summary now output the same format. (GH9116)

  • TimedeltaIndex.freqstr now output the same string format as DatetimeIndex. (GH9116)

  • Bar and horizontal bar plots no longer add a dashed line along the info axis. The prior style can be achieved with matplotlib’s axhline or axvline methods (GH9088).

  • Series accessors .dt, .cat and .str now raise AttributeError instead of TypeError if the series does not contain the appropriate type of data (GH9617). This follows Python’s built-in exception hierarchy more closely and ensures that tests like hasattr(s, 'cat') are consistent on both Python 2 and 3.

  • Series now supports bitwise operation for integral types (GH9016). Previously even if the input dtypes were integral, the output dtype was coerced to bool.

    Previous Behavior

    In [2]: pd.Series([0,1,2,3], list('abcd')) | pd.Series([4,4,4,4], list('abcd'))
    a    True
    b    True
    c    True
    d    True
    dtype: bool

    New Behavior. If the input dtypes are integral, the output dtype is also integral and the output values are the result of the bitwise operation.

    In [2]: pd.Series([0,1,2,3], list('abcd')) | pd.Series([4,4,4,4], list('abcd'))
    a    4
    b    5
    c    6
    d    7
    dtype: int64
  • During division involving a Series or DataFrame, 0/0 and 0//0 now give np.nan instead of np.inf. (GH9144, GH8445)

    Previous Behavior

    In [2]: p = pd.Series([0, 1])
    In [3]: p / 0
    0    inf
    1    inf
    dtype: float64
    In [4]: p // 0
    0    inf
    1    inf
    dtype: float64

    New Behavior

    In [59]: p = pd.Series([0, 1])
    In [60]: p / 0
    0    NaN
    1    inf
    dtype: float64
    In [61]: p // 0
    0    NaN
    1    inf
    dtype: float64
  • Series.values_counts and Series.describe for categorical data will now put NaN entries at the end. (GH9443)

  • Series.describe for categorical data will now give counts and frequencies of 0, not NaN, for unused categories (GH9443)

  • Due to a bug fix, looking up a partial string label with DatetimeIndex.asof now includes values that match the string, even if they are after the start of the partial string label (GH9258).

    Old behavior:

    In [4]: pd.to_datetime(['2000-01-31', '2000-02-28']).asof('2000-02')
    Out[4]: Timestamp('2000-01-31 00:00:00')

    Fixed behavior:

    In [62]: pd.to_datetime(['2000-01-31', '2000-02-28']).asof('2000-02')
    Out[62]: Timestamp('2000-02-28 00:00:00')

    To reproduce the old behavior, simply add more precision to the label (e.g., use 2000-02-01 instead of 2000-02).


  • The rplot trellis plotting interface is deprecated and will be removed in a future version. We refer to external packages like seaborn for similar but more refined functionality (GH3445). The documentation includes some examples how to convert your existing code using rplot to seaborn: rplot docs.
  • The pandas.sandbox.qtpandas interface is deprecated and will be removed in a future version. We refer users to the external package pandas-qt. (GH9615)
  • The pandas.rpy interface is deprecated and will be removed in a future version. Similar functionaility can be accessed thru the rpy2 project (GH9602)
  • Adding DatetimeIndex/PeriodIndex to another DatetimeIndex/PeriodIndex is being deprecated as a set-operation. This will be changed to a TypeError in a future version. .union() should be used for the union set operation. (GH9094)
  • Subtracting DatetimeIndex/PeriodIndex from another DatetimeIndex/PeriodIndex is being deprecated as a set-operation. This will be changed to an actual numeric subtraction yielding a TimeDeltaIndex in a future version. .difference() should be used for the differencing set operation. (GH9094)

Removal of prior version deprecations/changes

  • DataFrame.pivot_table and crosstab‘s rows and cols keyword arguments were removed in favor of index and columns (GH6581)
  • DataFrame.to_excel and DataFrame.to_csv cols keyword argument was removed in favor of columns (GH6581)
  • Removed convert_dummies in favor of get_dummies (GH6581)
  • Removed value_range in favor of describe (GH6581)

Performance Improvements

  • Fixed a performance regression for .loc indexing with an array or list-like (GH9126:).
  • DataFrame.to_json 30x performance improvement for mixed dtype frames. (GH9037)
  • Performance improvements in MultiIndex.duplicated by working with labels instead of values (GH9125)
  • Improved the speed of nunique by calling unique instead of value_counts (GH9129, GH7771)
  • Performance improvement of up to 10x in DataFrame.count and DataFrame.dropna by taking advantage of homogeneous/heterogeneous dtypes appropriately (GH9136)
  • Performance improvement of up to 20x in DataFrame.count when using a MultiIndex and the level keyword argument (GH9163)
  • Performance and memory usage improvements in merge when key space exceeds int64 bounds (GH9151)
  • Performance improvements in multi-key groupby (GH9429)
  • Performance improvements in MultiIndex.sortlevel (GH9445)
  • Performance and memory usage improvements in DataFrame.duplicated (GH9398)
  • Cythonized Period (GH9440)
  • Decreased memory usage on to_hdf (GH9648)

Bug Fixes

  • Changed .to_html to remove leading/trailing spaces in table body (GH4987)
  • Fixed issue using read_csv on s3 with Python 3 (GH9452)
  • Fixed compatibility issue in DatetimeIndex affecting architectures where numpy.int_ defaults to numpy.int32 (GH8943)
  • Bug in Panel indexing with an object-like (GH9140)
  • Bug in the returned Series.dt.components index was reset to the default index (GH9247)
  • Bug in Categorical.__getitem__/__setitem__ with listlike input getting incorrect results from indexer coercion (GH9469)
  • Bug in partial setting with a DatetimeIndex (GH9478)
  • Bug in groupby for integer and datetime64 columns when applying an aggregator that caused the value to be changed when the number was sufficiently large (GH9311, GH6620)
  • Fixed bug in to_sql when mapping a Timestamp object column (datetime column with timezone info) to the appropriate sqlalchemy type (GH9085).
  • Fixed bug in to_sql dtype argument not accepting an instantiated SQLAlchemy type (GH9083).
  • Bug in .loc partial setting with a np.datetime64 (GH9516)
  • Incorrect dtypes inferred on datetimelike looking Series & on .xs slices (GH9477)
  • Items in Categorical.unique() (and s.unique() if s is of dtype category) now appear in the order in which they are originally found, not in sorted order (GH9331). This is now consistent with the behavior for other dtypes in pandas.
  • Fixed bug on big endian platforms which produced incorrect results in StataReader (GH8688).
  • Bug in MultiIndex.has_duplicates when having many levels causes an indexer overflow (GH9075, GH5873)
  • Bug in pivot and unstack where nan values would break index alignment (GH4862, GH7401, GH7403, GH7405, GH7466, GH9497)
  • Bug in left join on multi-index with sort=True or null values (GH9210).
  • Bug in MultiIndex where inserting new keys would fail (GH9250).
  • Bug in groupby when key space exceeds int64 bounds (GH9096).
  • Bug in unstack with TimedeltaIndex or DatetimeIndex and nulls (GH9491).
  • Bug in rank where comparing floats with tolerance will cause inconsistent behaviour (GH8365).
  • Fixed character encoding bug in read_stata and StataReader when loading data from a URL (GH9231).
  • Bug in adding offsets.Nano to other offets raises TypeError (GH9284)
  • Bug in DatetimeIndex iteration, related to (GH8890), fixed in (GH9100)
  • Bugs in resample around DST transitions. This required fixing offset classes so they behave correctly on DST transitions. (GH5172, GH8744, GH8653, GH9173, GH9468).
  • Bug in binary operator method (eg .mul()) alignment with integer levels (GH9463).
  • Bug in boxplot, scatter and hexbin plot may show an unnecessary warning (GH8877)
  • Bug in subplot with layout kw may show unnecessary warning (GH9464)
  • Bug in using grouper functions that need passed thru arguments (e.g. axis), when using wrapped function (e.g. fillna), (GH9221)
  • DataFrame now properly supports simultaneous copy and dtype arguments in constructor (GH9099)
  • Bug in read_csv when using skiprows on a file with CR line endings with the c engine. (GH9079)
  • isnull now detects NaT in PeriodIndex (GH9129)
  • Bug in groupby .nth() with a multiple column groupby (GH8979)
  • Bug in DataFrame.where and Series.where coerce numerics to string incorrectly (GH9280)
  • Bug in DataFrame.where and Series.where raise ValueError when string list-like is passed. (GH9280)
  • Accessing Series.str methods on with non-string values now raises TypeError instead of producing incorrect results (GH9184)
  • Bug in DatetimeIndex.__contains__ when index has duplicates and is not monotonic increasing (GH9512)
  • Fixed division by zero error for Series.kurt() when all values are equal (GH9197)
  • Fixed issue in the xlsxwriter engine where it added a default ‘General’ format to cells if no other format wass applied. This prevented other row or column formatting being applied. (GH9167)
  • Fixes issue with index_col=False when usecols is also specified in read_csv. (GH9082)
  • Bug where wide_to_long would modify the input stubnames list (GH9204)
  • Bug in to_sql not storing float64 values using double precision. (GH9009)
  • SparseSeries and SparsePanel now accept zero argument constructors (same as their non-sparse counterparts) (GH9272).
  • Regression in merging Categorical and object dtypes (GH9426)
  • Bug in read_csv with buffer overflows with certain malformed input files (GH9205)
  • Bug in groupby MultiIndex with missing pair (GH9049, GH9344)
  • Fixed bug in Series.groupby where grouping on MultiIndex levels would ignore the sort argument (GH9444)
  • Fix bug in DataFrame.Groupby where sort=False is ignored in the case of Categorical columns. (GH8868)
  • Fixed bug with reading CSV files from Amazon S3 on python 3 raising a TypeError (GH9452)
  • Bug in the Google BigQuery reader where the ‘jobComplete’ key may be present but False in the query results (GH8728)
  • Bug in Series.values_counts with excluding NaN for categorical type Series with dropna=True (GH9443)
  • Fixed mising numeric_only option for DataFrame.std/var/sem (GH9201)
  • Support constructing Panel or Panel4D with scalar data (GH8285)
  • Series text representation disconnected from max_rows/max_columns (GH7508).

  • Series number formatting inconsistent when truncated (GH8532).

    Previous Behavior

    In [2]: pd.options.display.max_rows = 10
    In [3]: s = pd.Series([1,1,1,1,1,1,1,1,1,1,0.9999,1,1]*10)
    In [4]: s
    0    1
    1    1
    2    1
    127    0.9999
    128    1.0000
    129    1.0000
    Length: 130, dtype: float64

    New Behavior

    0      1.0000
    1      1.0000
    2      1.0000
    3      1.0000
    4      1.0000
    125    1.0000
    126    1.0000
    127    0.9999
    128    1.0000
    129    1.0000
    dtype: float64
  • A Spurious SettingWithCopy Warning was generated when setting a new item in a frame in some cases (GH8730)

    The following would previously report a SettingWithCopy Warning.

    In [1]: df1 = DataFrame({'x': Series(['a','b','c']), 'y': Series(['d','e','f'])})
    In [2]: df2 = df1[['x']]
    In [3]: df2['y'] = ['g', 'h', 'i']

v0.15.2 (December 12, 2014)

This is a minor release from 0.15.1 and includes a large number of bug fixes along with several new features, enhancements, and performance improvements. A small number of API changes were necessary to fix existing bugs. We recommend that all users upgrade to this version.

API changes

  • Indexing in MultiIndex beyond lex-sort depth is now supported, though a lexically sorted index will have a better performance. (GH2646)

    In [1]: df = pd.DataFrame({'jim':[0, 0, 1, 1],
       ...:                    'joe':['x', 'x', 'z', 'y'],
       ...:                    'jolie':np.random.rand(4)}).set_index(['jim', 'joe'])
    In [2]: df
    jim joe          
    0   x    0.043324
        x    0.561433
    1   z    0.329668
        y    0.502967
    In [3]: df.index.lexsort_depth
    Out[3]: 1
    # in prior versions this would raise a KeyError
    # will now show a PerformanceWarning
    In [4]: df.loc[(1, 'z')]
    jim joe          
    1   z    0.329668
    # lexically sorting
    In [5]: df2 = df.sortlevel()
    In [6]: df2
    jim joe          
    0   x    0.043324
        x    0.561433
    1   y    0.502967
        z    0.329668
    In [7]: df2.index.lexsort_depth
    Out[7]: 2
    In [8]: df2.loc[(1,'z')]
    jim joe          
    1   z    0.329668
  • Bug in unique of Series with category dtype, which returned all categories regardless whether they were “used” or not (see GH8559 for the discussion). Previous behaviour was to return all categories:

    In [3]: cat = pd.Categorical(['a', 'b', 'a'], categories=['a', 'b', 'c'])
    In [4]: cat
    [a, b, a]
    Categories (3, object): [a < b < c]
    In [5]: cat.unique()
    Out[5]: array(['a', 'b', 'c'], dtype=object)

    Now, only the categories that do effectively occur in the array are returned:

    In [9]: cat = pd.Categorical(['a', 'b', 'a'], categories=['a', 'b', 'c'])
    In [10]: cat.unique()
    [a, b]
    Categories (2, object): [a, b]
  • Series.all and Series.any now support the level and skipna parameters. Series.all, Series.any, Index.all, and Index.any no longer support the out and keepdims parameters, which existed for compatibility with ndarray. Various index types no longer support the all and any aggregation functions and will now raise TypeError. (GH8302).

  • Allow equality comparisons of Series with a categorical dtype and object dtype; previously these would raise TypeError (GH8938)

  • Bug in NDFrame: conflicting attribute/column names now behave consistently between getting and setting. Previously, when both a column and attribute named y existed, data.y would return the attribute, while data.y = z would update the column (GH8994)

    In [11]: data = pd.DataFrame({'x':[1, 2, 3]})
    In [12]: data.y = 2
    In [13]: data['y'] = [2, 4, 6]
    In [14]: data
       x  y
    0  1  2
    1  2  4
    2  3  6
    # this assignment was inconsistent
    In [15]: data.y = 5

    Old behavior:

    In [6]: data.y
    Out[6]: 2
    In [7]: data['y'].values
    Out[7]: array([5, 5, 5])

    New behavior:

    In [16]: data.y
    Out[16]: 5
    In [17]: data['y'].values
    Out[17]: array([2, 4, 6])
  • Timestamp('now') is now equivalent to in that it returns the local time rather than UTC. Also, Timestamp('today') is now equivalent to and both have tz as a possible argument. (GH9000)

  • Fix negative step support for label-based slices (GH8753)

    Old behavior:

    In [1]: s = pd.Series(np.arange(3), ['a', 'b', 'c'])
    a    0
    b    1
    c    2
    dtype: int64
    In [2]: s.loc['c':'a':-1]
    c    2
    dtype: int64

    New behavior:

    In [18]: s = pd.Series(np.arange(3), ['a', 'b', 'c'])
    In [19]: s.loc['c':'a':-1]
    c    2
    b    1
    a    0
    dtype: int64


Categorical enhancements:

  • Added ability to export Categorical data to Stata (GH8633). See here for limitations of categorical variables exported to Stata data files.
  • Added flag order_categoricals to StataReader and read_stata to select whether to order imported categorical data (GH8836). See here for more information on importing categorical variables from Stata data files.
  • Added ability to export Categorical data to to/from HDF5 (GH7621). Queries work the same as if it was an object array. However, the category dtyped data is stored in a more efficient manner. See here for an example and caveats w.r.t. prior versions of pandas.
  • Added support for searchsorted() on Categorical class (GH8420).

Other enhancements:

  • Added the ability to specify the SQL type of columns when writing a DataFrame to a database (GH8778). For example, specifying to use the sqlalchemy String type instead of the default Text type for string columns:

    from sqlalchemy.types import String
    data.to_sql('data_dtype', engine, dtype={'Col_1': String})
  • Series.all and Series.any now support the level and skipna parameters (GH8302):

    In [20]: s = pd.Series([False, True, False], index=[0, 0, 1])
    In [21]: s.any(level=0)
    0     True
    1    False
    dtype: bool
  • Panel now supports the all and any aggregation functions. (GH8302):

    In [22]: p = pd.Panel(np.random.rand(2, 5, 4) > 0.1)
    In [23]: p.all()
           0      1
    0   True  False
    1   True   True
    2   True   True
    3  False   True
  • Added support for utcfromtimestamp(), fromtimestamp(), and combine() on Timestamp class (GH5351).

  • Added Google Analytics ( basic documentation (GH8835). See here.

  • Timedelta arithmetic returns NotImplemented in unknown cases, allowing extensions by custom classes (GH8813).

  • Timedelta now supports arithemtic with numpy.ndarray objects of the appropriate dtype (numpy 1.8 or newer only) (GH8884).

  • Added Timedelta.to_timedelta64() method to the public API (GH8884).

  • Added gbq.generate_bq_schema() function to the gbq module (GH8325).

  • Series now works with map objects the same way as generators (GH8909).

  • Added context manager to HDFStore for automatic closing (GH8791).

  • to_datetime gains an exact keyword to allow for a format to not require an exact match for a provided format string (if its False). exact defaults to True (meaning that exact matching is still the default) (GH8904)

  • Added axvlines boolean option to parallel_coordinates plot function, determines whether vertical lines will be printed, default is True

  • Added ability to read table footers to read_html (GH8552)

  • to_sql now infers datatypes of non-NA values for columns that contain NA values and have dtype object (GH8778).


  • Reduce memory usage when skiprows is an integer in read_csv (GH8681)
  • Performance boost for to_datetime conversions with a passed format=, and the exact=False (GH8904)

Bug Fixes

  • Bug in concat of Series with category dtype which were coercing to object. (GH8641)
  • Bug in Timestamp-Timestamp not returning a Timedelta type and datelike-datelike ops with timezones (GH8865)
  • Made consistent a timezone mismatch exception (either tz operated with None or incompatible timezone), will now return TypeError rather than ValueError (a couple of edge cases only), (GH8865)
  • Bug in using a pd.Grouper(key=...) with no level/axis or level only (GH8795, GH8866)
  • Report a TypeError when invalid/no parameters are passed in a groupby (GH8015)
  • Bug in packaging pandas with py2app/cx_Freeze (GH8602, GH8831)
  • Bug in groupby signatures that didn’t include *args or **kwargs (GH8733).
  • now raises RemoteDataError when no expiry dates are available from Yahoo and when it receives no data from Yahoo (GH8761), (GH8783).
  • Unclear error message in csv parsing when passing dtype and names and the parsed data is a different data type (GH8833)
  • Bug in slicing a multi-index with an empty list and at least one boolean indexer (GH8781)
  • now raises RemoteDataError when no expiry dates are available from Yahoo (GH8761).
  • Timedelta kwargs may now be numpy ints and floats (GH8757).
  • Fixed several outstanding bugs for Timedelta arithmetic and comparisons (GH8813, GH5963, GH5436).
  • sql_schema now generates dialect appropriate CREATE TABLE statements (GH8697)
  • slice string method now takes step into account (GH8754)
  • Bug in BlockManager where setting values with different type would break block integrity (GH8850)
  • Bug in DatetimeIndex when using time object as key (GH8667)
  • Bug in merge where how='left' and sort=False would not preserve left frame order (GH7331)
  • Bug in MultiIndex.reindex where reindexing at level would not reorder labels (GH4088)
  • Bug in certain operations with dateutil timezones, manifesting with dateutil 2.3 (GH8639)
  • Regression in DatetimeIndex iteration with a Fixed/Local offset timezone (GH8890)
  • Bug in to_datetime when parsing a nanoseconds using the %f format (GH8989)
  • now raises RemoteDataError when no expiry dates are available from Yahoo and when it receives no data from Yahoo (GH8761), (GH8783).
  • Fix: The font size was only set on x axis if vertical or the y axis if horizontal. (GH8765)
  • Fixed division by 0 when reading big csv files in python 3 (GH8621)
  • Bug in outputing a Multindex with to_html,index=False which would add an extra column (GH8452)
  • Imported categorical variables from Stata files retain the ordinal information in the underlying data (GH8836).
  • Defined .size attribute across NDFrame objects to provide compat with numpy >= 1.9.1; buggy with np.array_split (GH8846)
  • Skip testing of histogram plots for matplotlib <= 1.2 (GH8648).
  • Bug where get_data_google returned object dtypes (GH3995)
  • Bug in DataFrame.stack(..., dropna=False) when the DataFrame’s columns is a MultiIndex whose labels do not reference all its levels. (GH8844)
  • Bug in that Option context applied on __enter__ (GH8514)
  • Bug in resample that causes a ValueError when resampling across multiple days and the last offset is not calculated from the start of the range (GH8683)
  • Bug where DataFrame.plot(kind='scatter') fails when checking if an np.array is in the DataFrame (GH8852)
  • Bug in pd.infer_freq/DataFrame.inferred_freq that prevented proper sub-daily frequency inference when the index contained DST days (GH8772).
  • Bug where index name was still used when plotting a series with use_index=False (GH8558).
  • Bugs when trying to stack multiple columns, when some (or all) of the level names are numbers (GH8584).
  • Bug in MultiIndex where __contains__ returns wrong result if index is not lexically sorted or unique (GH7724)
  • BUG CSV: fix problem with trailing whitespace in skipped rows, (GH8679), (GH8661), (GH8983)
  • Regression in Timestamp does not parse ‘Z’ zone designator for UTC (GH8771)
  • Bug in StataWriter the produces writes strings with 244 characters irrespective of actual size (GH8969)
  • Fixed ValueError raised by cummin/cummax when datetime64 Series contains NaT. (GH8965)
  • Bug in Datareader returns object dtype if there are missing values (GH8980)
  • Bug in plotting if sharex was enabled and index was a timeseries, would show labels on multiple axes (GH3964).
  • Bug where passing a unit to the TimedeltaIndex constructor applied the to nano-second conversion twice. (GH9011).
  • Bug in plotting of a period-like array (GH9012)

v0.15.1 (November 9, 2014)

This is a minor bug-fix release from 0.15.0 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all users upgrade to this version.

API changes

  • s.dt.hour and other .dt accessors will now return np.nan for missing values (rather than previously -1), (GH8689)

    In [1]: s = Series(date_range('20130101',periods=5,freq='D'))
    In [2]: s.iloc[2] = np.nan
    In [3]: s
    0   2013-01-01
    1   2013-01-02
    2          NaT
    3   2013-01-04
    4   2013-01-05
    dtype: datetime64[ns]

    previous behavior:

    In [6]: s.dt.hour
    0    0
    1    0
    2   -1
    3    0
    4    0
    dtype: int64

    current behavior:

    In [4]: s.dt.hour
    0    0.0
    1    0.0
    2    NaN
    3    0.0
    4    0.0
    dtype: float64
  • groupby with as_index=False will not add erroneous extra columns to result (GH8582):

    In [5]: np.random.seed(2718281)
    In [6]: df = pd.DataFrame(np.random.randint(0, 100, (10, 2)),
       ...:                   columns=['jim', 'joe'])
    In [7]: df.head()
       jim  joe
    0   61   81
    1   96   49
    2   55   65
    3   72   51
    4   77   12
    In [8]: ts = pd.Series(5 * np.random.randint(0, 3, 10))

    previous behavior:

    In [4]: df.groupby(ts, as_index=False).max()
       NaN  jim  joe
    0    0   72   83
    1    5   77   84
    2   10   96   65

    current behavior:

    In [9]: df.groupby(ts, as_index=False).max()
       jim  joe
    0   72   83
    1   77   84
    2   96   65
  • groupby will not erroneously exclude columns if the column name conflics with the grouper name (GH8112):

    In [10]: df = pd.DataFrame({'jim': range(5), 'joe': range(5, 10)})
    In [11]: df
       jim  joe
    0    0    5
    1    1    6
    2    2    7
    3    3    8
    4    4    9
    In [12]: gr = df.groupby(df['jim'] < 2)

    previous behavior (excludes 1st column from output):

    In [4]: gr.apply(sum)
    False   24
    True    11

    current behavior:

    In [13]: gr.apply(sum)
           jim  joe
    False    9   24
    True     1   11
  • Support for slicing with monotonic decreasing indexes, even if start or stop is not found in the index (GH7860):

    In [14]: s = pd.Series(['a', 'b', 'c', 'd'], [4, 3, 2, 1])
    In [15]: s
    4    a
    3    b
    2    c
    1    d
    dtype: object

    previous behavior:

    In [8]: s.loc[3.5:1.5]
    KeyError: 3.5

    current behavior:

    In [16]: s.loc[3.5:1.5]
    3    b
    2    c
    dtype: object
  • has been fixed for a change in the format of the Yahoo Options page (GH8612), (GH8741)


    As a result of a change in Yahoo’s option page layout, when an expiry date is given, Options methods now return data for a single expiry date. Previously, methods returned all data for the selected month.

    The month and year parameters have been undeprecated and can be used to get all options data for a given month.

    If an expiry date that is not valid is given, data for the next expiry after the given date is returned.

    Option data frames are now saved on the instance as callsYYMMDD or putsYYMMDD. Previously they were saved as callsMMYY and putsMMYY. The next expiry is saved as calls and puts.

    New features:

    • The expiry parameter can now be a single date or a list-like object containing dates.
    • A new property expiry_dates was added, which returns all available expiry dates.

    Current behavior:

    In [17]: from import Options
    In [18]: aapl = Options('aapl','yahoo')
    In [19]: aapl.get_call_data().iloc[0:5,0:1]
    Strike Expiry     Type Symbol                    
    55.0   2016-05-06 call AAPL160506C00055000  37.74
    80.0   2016-05-06 call AAPL160506C00080000  13.75
    85.0   2016-05-06 call AAPL160506C00085000   9.25
    86.0   2016-05-06 call AAPL160506C00086000   6.91
    87.0   2016-05-06 call AAPL160506C00087000   7.21
    In [20]: aapl.expiry_dates
    [, 5, 6),, 5, 13),, 5, 20),, 5, 27),, 6, 3),, 6, 10),, 6, 17),, 7, 15),, 8, 19),, 10, 21),, 1, 20),, 3, 17),, 6, 16),, 1, 19)]
    In [21]: aapl.get_near_stock_price(expiry=aapl.expiry_dates[0:3]).iloc[0:5,0:1]
    Strike Expiry     Type Symbol                   
    93.5   2016-05-13 call AAPL160513C00093500  1.52
           2016-05-20 call AAPL160520C00093500  2.15
    94.0   2016-05-06 call AAPL160506C00094000  0.95
           2016-05-13 call AAPL160513C00094000  1.46
           2016-05-20 call AAPL160520C00094000  1.92

    See the Options documentation in Remote Data

  • pandas now also registers the datetime64 dtype in matplotlib’s units registry to plot such values as datetimes. This is activated once pandas is imported. In previous versions, plotting an array of datetime64 values will have resulted in plotted integer values. To keep the previous behaviour, you can do del matplotlib.units.registry[np.datetime64] (GH8614).


  • concat permits a wider variety of iterables of pandas objects to be passed as the first parameter (GH8645):

    In [22]: from collections import deque
    In [23]: df1 = pd.DataFrame([1, 2, 3])
    In [24]: df2 = pd.DataFrame([4, 5, 6])

    previous behavior:

    In [7]: pd.concat(deque((df1, df2)))
    TypeError: first argument must be a list-like of pandas objects, you passed an object of type "deque"

    current behavior:

    In [25]: pd.concat(deque((df1, df2)))
    0  1
    1  2
    2  3
    0  4
    1  5
    2  6
  • Represent MultiIndex labels with a dtype that utilizes memory based on the level size. In prior versions, the memory usage was a constant 8 bytes per element in each level. In addition, in prior versions, the reported memory usage was incorrect as it didn’t show the usage for the memory occupied by the underling data array. (GH8456)

    In [26]: dfi = DataFrame(1,index=pd.MultiIndex.from_product([['a'],range(1000)]),columns=['A'])

    previous behavior:

    # this was underreported in prior versions
    In [1]: dfi.memory_usage(index=True)
    Index    8000 # took about 24008 bytes in < 0.15.1
    A        8000
    dtype: int64

    current behavior:

    In [27]: dfi.memory_usage(index=True)
    Index    8000
    A        8000
    dtype: int64
  • Added Index properties is_monotonic_increasing and is_monotonic_decreasing (GH8680).

  • Added option to select columns when importing Stata files (GH7935)

  • Qualify memory usage in by adding + if it is a lower bound (GH8578)

  • Raise errors in certain aggregation cases where an argument such as numeric_only is not handled (GH8592).

  • Added support for 3-character ISO and non-standard country codes in (GH8482)

  • World Bank data requests now will warn/raise based on an errors argument, as well as a list of hard-coded country codes and the World Bank’s JSON response. In prior versions, the error messages didn’t look at the World Bank’s JSON response. Problem-inducing input were simply dropped prior to the request. The issue was that many good countries were cropped in the hard-coded approach. All countries will work now, but some bad countries will raise exceptions because some edge cases break the entire response. (GH8482)

  • Added option to Series.str.split() to return a DataFrame rather than a Series (GH8428)

  • Added option to|True|False) to override the default display options and force showing of the null-counts (GH8701)

Bug Fixes

  • Bug in unpickling of a CustomBusinessDay object (GH8591)
  • Bug in coercing Categorical to a records array, e.g. df.to_records() (GH8626)
  • Bug in Categorical not created properly with Series.to_frame() (GH8626)
  • Bug in coercing in astype of a Categorical of a passed pd.Categorical (this now raises TypeError correctly), (GH8626)
  • Bug in cut/qcut when using Series and retbins=True (GH8589)
  • Bug in writing Categorical columns to an SQL database with to_sql (GH8624).
  • Bug in comparing Categorical of datetime raising when being compared to a scalar datetime (GH8687)
  • Bug in selecting from a Categorical with .iloc (GH8623)
  • Bug in groupby-transform with a Categorical (GH8623)
  • Bug in duplicated/drop_duplicates with a Categorical (GH8623)
  • Bug in Categorical reflected comparison operator raising if the first argument was a numpy array scalar (e.g. np.int64) (GH8658)
  • Bug in Panel indexing with a list-like (GH8710)
  • Compat issue is DataFrame.dtypes when options.mode.use_inf_as_null is True (GH8722)
  • Bug in read_csv, dialect parameter would not take a string (:issue: 8703)
  • Bug in slicing a multi-index level with an empty-list (GH8737)
  • Bug in numeric index operations of add/sub with Float/Index Index with numpy arrays (GH8608)
  • Bug in setitem with empty indexer and unwanted coercion of dtypes (GH8669)
  • Bug in ix/loc block splitting on setitem (manifests with integer-like dtypes, e.g. datetime64) (GH8607)
  • Bug when doing label based indexing with integers not found in the index for non-unique but monotonic indexes (GH8680).
  • Bug when indexing a Float64Index with np.nan on numpy 1.7 (GH8980).
  • Fix shape attribute for MultiIndex (GH8609)
  • Bug in GroupBy where a name conflict between the grouper and columns would break groupby operations (GH7115, GH8112)
  • Fixed a bug where plotting a column y and specifying a label would mutate the index name of the original DataFrame (GH8494)
  • Fix regression in plotting of a DatetimeIndex directly with matplotlib (GH8614).
  • Bug in date_range where partially-specified dates would incorporate current date (GH6961)
  • Bug in Setting by indexer to a scalar value with a mixed-dtype Panel4d was failing (GH8702)
  • Bug where DataReader‘s would fail if one of the symbols passed was invalid. Now returns data for valid symbols and np.nan for invalid (GH8494)
  • Bug in get_quote_yahoo that wouldn’t allow non-float return values (GH5229).

v0.15.0 (October 18, 2014)

This is a major release from 0.14.1 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all users upgrade to this version.


pandas >= 0.15.0 will no longer support compatibility with NumPy versions < 1.7.0. If you want to use the latest versions of pandas, please upgrade to NumPy >= 1.7.0 (GH7711)


In 0.15.0 Index has internally been refactored to no longer sub-class ndarray but instead subclass PandasObject, similarly to the rest of the pandas objects. This change allows very easy sub-classing and creation of new index types. This should be a transparent change with only very limited API implications (See the Internal Refactoring)


The refactorings in Categorical changed the two argument constructor from “codes/labels and levels” to “values and levels (now called ‘categories’)”. This can lead to subtle bugs. If you use Categorical directly, please audit your code before updating to this pandas version and change it to use the from_codes() constructor. See more on Categorical here

New features

Categoricals in Series/DataFrame

Categorical can now be included in Series and DataFrames and gained new methods to manipulate. Thanks to Jan Schulz for much of this API/implementation. (GH3943, GH5313, GH5314, GH7444, GH7839, GH7848, GH7864, GH7914, GH7768, GH8006, GH3678, GH8075, GH8076, GH8143, GH8453, GH8518).

For full docs, see the categorical introduction and the API documentation.

In [1]: df = DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})

In [2]: df["grade"] = df["raw_grade"].astype("category")

In [3]: df["grade"]
0    a
1    b
2    b
3    a
4    a
5    e
Name: grade, dtype: category
Categories (3, object): [a, b, e]

# Rename the categories
In [4]: df["grade"].cat.categories = ["very good", "good", "very bad"]

# Reorder the categories and simultaneously add the missing categories
In [5]: df["grade"] = df["grade"].cat.set_categories(["very bad", "bad", "medium", "good", "very good"])

In [6]: df["grade"]
0    very good
1         good
2         good
3    very good
4    very good
5     very bad
Name: grade, dtype: category
Categories (5, object): [very bad, bad, medium, good, very good]

In [7]: df.sort("grade")
   id raw_grade      grade
5   6         e   very bad
1   2         b       good
2   3         b       good
0   1         a  very good
3   4         a  very good
4   5         a  very good

In [8]: df.groupby("grade").size()
very bad     1
bad          0
medium       0
good         2
very good    3
dtype: int64
  • pandas.core.group_agg and pandas.core.factor_agg were removed. As an alternative, construct a dataframe and use df.groupby(<group>).agg(<func>).
  • Supplying “codes/labels and levels” to the Categorical constructor is not supported anymore. Supplying two arguments to the constructor is now interpreted as “values and levels (now called ‘categories’)”. Please change your code to use the from_codes() constructor.
  • The Categorical.labels attribute was renamed to and is read only. If you want to manipulate codes, please use one of the API methods on Categoricals.
  • The Categorical.levels attribute is renamed to Categorical.categories.


We introduce a new scalar type Timedelta, which is a subclass of datetime.timedelta, and behaves in a similar manner, but allows compatibility with np.timedelta64 types as well as a host of custom representation, parsing, and attributes. This type is very similar to how Timestamp works for datetimes. It is a nice-API box for the type. See the docs. (GH3009, GH4533, GH8209, GH8187, GH8190, GH7869, GH7661, GH8345, GH8471)


Timedelta scalars (and TimedeltaIndex) component fields are not the same as the component fields on a datetime.timedelta object. For example, .seconds on a datetime.timedelta object returns the total number of seconds combined between hours, minutes and seconds. In contrast, the pandas Timedelta breaks out hours, minutes, microseconds and nanoseconds separately.

# Timedelta accessor
In [9]: tds = Timedelta('31 days 5 min 3 sec')

In [10]: tds.minutes
Out[10]: 5L

In [11]: tds.seconds
Out[11]: 3L

# datetime.timedelta accessor
# this is 5 minutes * 60 + 3 seconds
In [12]: tds.to_pytimedelta().seconds
Out[12]: 303

Note: this is no longer true starting from v0.16.0, where full compatibility with datetime.timedelta is introduced. See the 0.16.0 whatsnew entry


Prior to 0.15.0 pd.to_timedelta would return a Series for list-like/Series input, and a np.timedelta64 for scalar input. It will now return a TimedeltaIndex for list-like input, Series for Series input, and Timedelta for scalar input.

The arguments to pd.to_timedelta are now (arg,unit='ns',box=True,coerce=False), previously were (arg,box=True,unit='ns') as these are more logical.

Consruct a scalar

In [9]: Timedelta('1 days 06:05:01.00003')
Out[9]: Timedelta('1 days 06:05:01.000030')

In [10]: Timedelta('15.5us')
Out[10]: Timedelta('0 days 00:00:00.000015')

In [11]: Timedelta('1 hour 15.5us')
Out[11]: Timedelta('0 days 01:00:00.000015')

# negative Timedeltas have this string repr
# to be more consistent with datetime.timedelta conventions
In [12]: Timedelta('-1us')
Out[12]: Timedelta('-1 days +23:59:59.999999')

# a NaT
In [13]: Timedelta('nan')
Out[13]: NaT

Access fields for a Timedelta

In [14]: td = Timedelta('1 hour 3m 15.5us')

In [15]: td.seconds
Out[15]: 3780

In [16]: td.microseconds
Out[16]: 15

In [17]: td.nanoseconds
Out[17]: 500

Construct a TimedeltaIndex

In [18]: TimedeltaIndex(['1 days','1 days, 00:00:05',
   ....:                 np.timedelta64(2,'D'),timedelta(days=2,seconds=2)])
TimedeltaIndex(['1 days 00:00:00', '1 days 00:00:05', '2 days 00:00:00',
                '2 days 00:00:02'],
               dtype='timedelta64[ns]', freq=None)

Constructing a TimedeltaIndex with a regular range

In [19]: timedelta_range('1 days',periods=5,freq='D')
Out[19]: TimedeltaIndex(['1 days', '2 days', '3 days', '4 days', '5 days'], dtype='timedelta64[ns]', freq='D')

In [20]: timedelta_range(start='1 days',end='2 days',freq='30T')
TimedeltaIndex(['1 days 00:00:00', '1 days 00:30:00', '1 days 01:00:00',
                '1 days 01:30:00', '1 days 02:00:00', '1 days 02:30:00',
                '1 days 03:00:00', '1 days 03:30:00', '1 days 04:00:00',
                '1 days 04:30:00', '1 days 05:00:00', '1 days 05:30:00',
                '1 days 06:00:00', '1 days 06:30:00', '1 days 07:00:00',
                '1 days 07:30:00', '1 days 08:00:00', '1 days 08:30:00',
                '1 days 09:00:00', '1 days 09:30:00', '1 days 10:00:00',
                '1 days 10:30:00', '1 days 11:00:00', '1 days 11:30:00',
                '1 days 12:00:00', '1 days 12:30:00', '1 days 13:00:00',
                '1 days 13:30:00', '1 days 14:00:00', '1 days 14:30:00',
                '1 days 15:00:00', '1 days 15:30:00', '1 days 16:00:00',
                '1 days 16:30:00', '1 days 17:00:00', '1 days 17:30:00',
                '1 days 18:00:00', '1 days 18:30:00', '1 days 19:00:00',
                '1 days 19:30:00', '1 days 20:00:00', '1 days 20:30:00',
                '1 days 21:00:00', '1 days 21:30:00', '1 days 22:00:00',
                '1 days 22:30:00', '1 days 23:00:00', '1 days 23:30:00',
                '2 days 00:00:00'],
               dtype='timedelta64[ns]', freq='30T')

You can now use a TimedeltaIndex as the index of a pandas object

In [21]: s = Series(np.arange(5),
   ....:            index=timedelta_range('1 days',periods=5,freq='s'))

In [22]: s
1 days 00:00:00    0
1 days 00:00:01    1
1 days 00:00:02    2
1 days 00:00:03    3
1 days 00:00:04    4
Freq: S, dtype: int64

You can select with partial string selections

In [23]: s['1 day 00:00:02']
Out[23]: 2

In [24]: s['1 day':'1 day 00:00:02']
1 days 00:00:00    0
1 days 00:00:01    1
1 days 00:00:02    2
Freq: S, dtype: int64

Finally, the combination of TimedeltaIndex with DatetimeIndex allow certain combination operations that are NaT preserving:

In [25]: tdi = TimedeltaIndex(['1 days',pd.NaT,'2 days'])

In [26]: tdi.tolist()
Out[26]: [Timedelta('1 days 00:00:00'), NaT, Timedelta('2 days 00:00:00')]

In [27]: dti = date_range('20130101',periods=3)

In [28]: dti.tolist()
[Timestamp('2013-01-01 00:00:00', offset='D'),
 Timestamp('2013-01-02 00:00:00', offset='D'),
 Timestamp('2013-01-03 00:00:00', offset='D')]

In [29]: (dti + tdi).tolist()
Out[29]: [Timestamp('2013-01-02 00:00:00'), NaT, Timestamp('2013-01-05 00:00:00')]

In [30]: (dti - tdi).tolist()
Out[30]: [Timestamp('2012-12-31 00:00:00'), NaT, Timestamp('2013-01-01 00:00:00')]
  • iteration of a Series e.g. list(Series(...)) of timedelta64[ns] would prior to v0.15.0 return np.timedelta64 for each element. These will now be wrapped in Timedelta.

Memory Usage

Implemented methods to find memory usage of a DataFrame. See the FAQ for more. (GH6852).

A new display option display.memory_usage (see Options and Settings) sets the default behavior of the memory_usage argument in the method. By default display.memory_usage is True.

In [31]: dtypes = ['int64', 'float64', 'datetime64[ns]', 'timedelta64[ns]',
   ....:           'complex128', 'object', 'bool']

In [32]: n = 5000

In [33]: data = dict([ (t, np.random.randint(100, size=n).astype(t))
   ....:                 for t in dtypes])

In [34]: df = DataFrame(data)

In [35]: df['categorical'] = df['object'].astype('category')

In [36]:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5000 entries, 0 to 4999
Data columns (total 8 columns):
bool               5000 non-null bool
complex128         5000 non-null complex128
datetime64[ns]     5000 non-null datetime64[ns]
float64            5000 non-null float64
int64              5000 non-null int64
object             5000 non-null object
timedelta64[ns]    5000 non-null timedelta64[ns]
categorical        5000 non-null category
dtypes: bool(1), category(1), complex128(1), datetime64[ns](1), float64(1), int64(1), object(1), timedelta64[ns](1)
memory usage: 284.1+ KB

Additionally memory_usage() is an available method for a dataframe object which returns the memory usage of each column.

In [37]: df.memory_usage(index=True)
Index                 72
bool                5000
complex128         80000
datetime64[ns]     40000
float64            40000
int64              40000
object             40000
timedelta64[ns]    40000
categorical         5800
dtype: int64

.dt accessor

Series has gained an accessor to succinctly return datetime like properties for the values of the Series, if its a datetime/period like Series. (GH7207) This will return a Series, indexed like the existing Series. See the docs

# datetime
In [38]: s = Series(date_range('20130101 09:10:12',periods=4))

In [39]: s
0   2013-01-01 09:10:12
1   2013-01-02 09:10:12
2   2013-01-03 09:10:12
3   2013-01-04 09:10:12
dtype: datetime64[ns]

In [40]: s.dt.hour
0    9
1    9
2    9
3    9
dtype: int64

In [41]: s.dt.second
0    12
1    12
2    12
3    12
dtype: int64

In [42]:
0    1
1    2
2    3
3    4
dtype: int64

In [43]: s.dt.freq
Out[43]: <Day>

This enables nice expressions like this:

In [44]: s[]
1   2013-01-02 09:10:12
dtype: datetime64[ns]

You can easily produce tz aware transformations:

In [45]: stz = s.dt.tz_localize('US/Eastern')

In [46]: stz
0   2013-01-01 09:10:12-05:00
1   2013-01-02 09:10:12-05:00
2   2013-01-03 09:10:12-05:00
3   2013-01-04 09:10:12-05:00
dtype: datetime64[ns, US/Eastern]

In [47]:
Out[47]: <DstTzInfo 'US/Eastern' LMT-1 day, 19:04:00 STD>

You can also chain these types of operations:

In [48]: s.dt.tz_localize('UTC').dt.tz_convert('US/Eastern')
0   2013-01-01 04:10:12-05:00
1   2013-01-02 04:10:12-05:00
2   2013-01-03 04:10:12-05:00
3   2013-01-04 04:10:12-05:00
dtype: datetime64[ns, US/Eastern]

The .dt accessor works for period and timedelta dtypes.

# period
In [49]: s = Series(period_range('20130101',periods=4,freq='D'))

In [50]: s
0   2013-01-01
1   2013-01-02
2   2013-01-03
3   2013-01-04
dtype: object

In [51]: s.dt.year
0    2013
1    2013
2    2013
3    2013
dtype: int64

In [52]:
0    1
1    2
2    3
3    4
dtype: int64
# timedelta
In [53]: s = Series(timedelta_range('1 day 00:00:05',periods=4,freq='s'))

In [54]: s
0   1 days 00:00:05
1   1 days 00:00:06
2   1 days 00:00:07
3   1 days 00:00:08
dtype: timedelta64[ns]

In [55]: s.dt.days
0    1
1    1
2    1
3    1
dtype: int64

In [56]: s.dt.seconds
0    5
1    6
2    7
3    8
dtype: int64

In [57]: s.dt.components
   days  hours  minutes  seconds  milliseconds  microseconds  nanoseconds
0     1      0        0        5             0             0            0
1     1      0        0        6             0             0            0
2     1      0        0        7             0             0            0
3     1      0        0        8             0             0            0

Timezone handling improvements

  • tz_localize(None) for tz-aware Timestamp and DatetimeIndex now removes timezone holding local time, previously this resulted in Exception or TypeError (GH7812)

    In [58]: ts = Timestamp('2014-08-01 09:00', tz='US/Eastern')
    In [59]: ts
    Out[59]: Timestamp('2014-08-01 09:00:00-0400', tz='US/Eastern')
    In [60]: ts.tz_localize(None)
    Out[60]: Timestamp('2014-08-01 09:00:00')
    In [61]: didx = DatetimeIndex(start='2014-08-01 09:00', freq='H', periods=10, tz='US/Eastern')
    In [62]: didx
    DatetimeIndex(['2014-08-01 09:00:00-04:00', '2014-08-01 10:00:00-04:00',
                   '2014-08-01 11:00:00-04:00', '2014-08-01 12:00:00-04:00',
                   '2014-08-01 13:00:00-04:00', '2014-08-01 14:00:00-04:00',
                   '2014-08-01 15:00:00-04:00', '2014-08-01 16:00:00-04:00',
                   '2014-08-01 17:00:00-04:00', '2014-08-01 18:00:00-04:00'],
                  dtype='datetime64[ns, US/Eastern]', freq='H')
    In [63]: didx.tz_localize(None)
    DatetimeIndex(['2014-08-01 09:00:00', '2014-08-01 10:00:00',
                   '2014-08-01 11:00:00', '2014-08-01 12:00:00',
                   '2014-08-01 13:00:00', '2014-08-01 14:00:00',
                   '2014-08-01 15:00:00', '2014-08-01 16:00:00',
                   '2014-08-01 17:00:00', '2014-08-01 18:00:00'],
                  dtype='datetime64[ns]', freq='H')
  • tz_localize now accepts the ambiguous keyword which allows for passing an array of bools indicating whether the date belongs in DST or not, ‘NaT’ for setting transition times to NaT, ‘infer’ for inferring DST/non-DST, and ‘raise’ (default) for an AmbiguousTimeError to be raised. See the docs for more details (GH7943)

  • DataFrame.tz_localize and DataFrame.tz_convert now accepts an optional level argument for localizing a specific level of a MultiIndex (GH7846)

  • Timestamp.tz_localize and Timestamp.tz_convert now raise TypeError in error cases, rather than Exception (GH8025)

  • a timeseries/index localized to UTC when inserted into a Series/DataFrame will preserve the UTC timezone (rather than being a naive datetime64[ns]) as object dtype (GH8411)

  • Timestamp.__repr__ displays info (GH7907)

Rolling/Expanding Moments improvements

  • rolling_min(), rolling_max(), rolling_cov(), and rolling_corr() now return objects with all NaN when len(arg) < min_periods <= window rather than raising. (This makes all rolling functions consistent in this behavior). (GH7766)

    Prior to 0.15.0

    In [64]: s = Series([10, 11, 12, 13])
    In [15]: rolling_min(s, window=10, min_periods=5)
    ValueError: min_periods (5) must be <= window (4)

    New behavior

    In [4]: pd.rolling_min(s, window=10, min_periods=5)
    0   NaN
    1   NaN
    2   NaN
    3   NaN
    dtype: float64
  • rolling_max(), rolling_min(), rolling_sum(), rolling_mean(), rolling_median(), rolling_std(), rolling_var(), rolling_skew(), rolling_kurt(), rolling_quantile(), rolling_cov(), rolling_corr(), rolling_corr_pairwise(), rolling_window(), and rolling_apply() with center=True previously would return a result of the same structure as the input arg with NaN in the final (window-1)/2 entries.

    Now the final (window-1)/2 entries of the result are calculated as if the input arg were followed by (window-1)/2 NaN values (or with shrinking windows, in the case of rolling_apply()). (GH7925, GH8269)

    Prior behavior (note final value is NaN):

    In [7]: rolling_sum(Series(range(4)), window=3, min_periods=0, center=True)
    0     1
    1     3
    2     6
    3   NaN
    dtype: float64

    New behavior (note final value is 5 = sum([2, 3, NaN])):

    In [7]: rolling_sum(Series(range(4)), window=3, min_periods=0, center=True)
    0    1
    1    3
    2    6
    3    5
    dtype: float64
  • rolling_window() now normalizes the weights properly in rolling mean mode (mean=True) so that the calculated weighted means (e.g. ‘triang’, ‘gaussian’) are distributed about the same means as those calculated without weighting (i.e. ‘boxcar’). See the note on normalization for further details. (GH7618)

    In [65]: s = Series([10.5, 8.8, 11.4, 9.7, 9.3])

    Behavior prior to 0.15.0:

    In [39]: rolling_window(s, window=3, win_type='triang', center=True)
    0         NaN
    1    6.583333
    2    6.883333
    3    6.683333
    4         NaN
    dtype: float64

    New behavior

    In [10]: pd.rolling_window(s, window=3, win_type='triang', center=True)
    0       NaN
    1     9.875
    2    10.325
    3    10.025
    4       NaN
    dtype: float64
  • Removed center argument from all expanding_ functions (see list), as the results produced when center=True did not make much sense. (GH7925)

  • Added optional ddof argument to expanding_cov() and rolling_cov(). The default value of 1 is backwards-compatible. (GH8279)

  • Documented the ddof argument to expanding_var(), expanding_std(), rolling_var(), and rolling_std(). These functions’ support of a ddof argument (with a default value of 1) was previously undocumented. (GH8064)

  • ewma(), ewmstd(), ewmvol(), ewmvar(), ewmcov(), and ewmcorr() now interpret min_periods in the same manner that the rolling_*() and expanding_*() functions do: a given result entry will be NaN if the (expanding, in this case) window does not contain at least min_periods values. The previous behavior was to set to NaN the min_periods entries starting with the first non- NaN value. (GH7977)

    Prior behavior (note values start at index 2, which is min_periods after index 0 (the index of the first non-empty value)):

    In [66]: s  = Series([1, None, None, None, 2, 3])
    In [51]: ewma(s, com=3., min_periods=2)
    0         NaN
    1         NaN
    2    1.000000
    3    1.000000
    4    1.571429
    5    2.189189
    dtype: float64

    New behavior (note values start at index 4, the location of the 2nd (since min_periods=2) non-empty value):

    In [2]: pd.ewma(s, com=3., min_periods=2)
    0         NaN
    1         NaN
    2         NaN
    3         NaN
    4    1.759644
    5    2.383784
    dtype: float64
  • ewmstd(), ewmvol(), ewmvar(), ewmcov(), and ewmcorr() now have an optional adjust argument, just like ewma() does, affecting how the weights are calculated. The default value of adjust is True, which is backwards-compatible. See Exponentially weighted moment functions for details. (GH7911)

  • ewma(), ewmstd(), ewmvol(), ewmvar(), ewmcov(), and ewmcorr() now have an optional ignore_na argument. When ignore_na=False (the default), missing values are taken into account in the weights calculation. When ignore_na=True (which reproduces the pre-0.15.0 behavior), missing values are ignored in the weights calculation. (GH7543)

    In [7]: pd.ewma(Series([None, 1., 8.]), com=2.)
    0    NaN
    1    1.0
    2    5.2
    dtype: float64
    In [8]: pd.ewma(Series([1., None, 8.]), com=2., ignore_na=True)  # pre-0.15.0 behavior
    0    1.0
    1    1.0
    2    5.2
    dtype: float64
    In [9]: pd.ewma(Series([1., None, 8.]), com=2., ignore_na=False)  # new default
    0    1.000000
    1    1.000000
    2    5.846154
    dtype: float64


    By default (ignore_na=False) the ewm*() functions’ weights calculation in the presence of missing values is different than in pre-0.15.0 versions. To reproduce the pre-0.15.0 calculation of weights in the presence of missing values one must specify explicitly ignore_na=True.

  • Bug in expanding_cov(), expanding_corr(), rolling_cov(), rolling_cor(), ewmcov(), and ewmcorr() returning results with columns sorted by name and producing an error for non-unique columns; now handles non-unique columns and returns columns in original order (except for the case of two DataFrames with pairwise=False, where behavior is unchanged) (GH7542)

  • Bug in rolling_count() and expanding_*() functions unnecessarily producing error message for zero-length data (GH8056)

  • Bug in rolling_apply() and expanding_apply() interpreting min_periods=0 as min_periods=1 (GH8080)

  • Bug in expanding_std() and expanding_var() for a single value producing a confusing error message (GH7900)

  • Bug in rolling_std() and rolling_var() for a single value producing 0 rather than NaN (GH7900)

  • Bug in ewmstd(), ewmvol(), ewmvar(), and ewmcov() calculation of de-biasing factors when bias=False (the default). Previously an incorrect constant factor was used, based on adjust=True, ignore_na=True, and an infinite number of observations. Now a different factor is used for each entry, based on the actual weights (analogous to the usual N/(N-1) factor). In particular, for a single point a value of NaN is returned when bias=False, whereas previously a value of (approximately) 0 was returned.

    For example, consider the following pre-0.15.0 results for ewmvar(..., bias=False), and the corresponding debiasing factors:

    In [67]: s = Series([1., 2., 0., 4.])
    In [89]: ewmvar(s, com=2., bias=False)
    0   -2.775558e-16
    1    3.000000e-01
    2    9.556787e-01
    3    3.585799e+00
    dtype: float64
    In [90]: ewmvar(s, com=2., bias=False) / ewmvar(s, com=2., bias=True)
    0    1.25
    1    1.25
    2    1.25
    3    1.25
    dtype: float64

    Note that entry 0 is approximately 0, and the debiasing factors are a constant 1.25. By comparison, the following 0.15.0 results have a NaN for entry 0, and the debiasing factors are decreasing (towards 1.25):

    In [14]: pd.ewmvar(s, com=2., bias=False)
    0         NaN
    1    0.500000
    2    1.210526
    3    4.089069
    dtype: float64
    In [15]: pd.ewmvar(s, com=2., bias=False) / pd.ewmvar(s, com=2., bias=True)
    0         NaN
    1    2.083333
    2    1.583333
    3    1.425439
    dtype: float64

    See Exponentially weighted moment functions for details. (GH7912)

Improvements in the sql io module

  • Added support for a chunksize parameter to to_sql function. This allows DataFrame to be written in chunks and avoid packet-size overflow errors (GH8062).

  • Added support for a chunksize parameter to read_sql function. Specifying this argument will return an iterator through chunks of the query result (GH2908).

  • Added support for writing and datetime.time object columns with to_sql (GH6932).

  • Added support for specifying a schema to read from/write to with read_sql_table and to_sql (GH7441, GH7952). For example:

    df.to_sql('table', engine, schema='other_schema')
    pd.read_sql_table('table', engine, schema='other_schema')
  • Added support for writing NaN values with to_sql (GH2754).

  • Added support for writing datetime64 columns with to_sql for all database flavors (GH7103).

Backwards incompatible API changes

Breaking changes

API changes related to Categorical (see here for more details):

  • The Categorical constructor with two arguments changed from “codes/labels and levels” to “values and levels (now called ‘categories’)”. This can lead to subtle bugs. If you use Categorical directly, please audit your code by changing it to use the from_codes() constructor.

    An old function call like (prior to 0.15.0):

    pd.Categorical([0,1,0,2,1], levels=['a', 'b', 'c'])

    will have to adapted to the following to keep the same behaviour:

    In [2]: pd.Categorical.from_codes([0,1,0,2,1], categories=['a', 'b', 'c'])
    [a, b, a, c, b]
    Categories (3, object): [a, b, c]

API changes related to the introduction of the Timedelta scalar (see above for more details):

  • Prior to 0.15.0 to_timedelta() would return a Series for list-like/Series input, and a np.timedelta64 for scalar input. It will now return a TimedeltaIndex for list-like input, Series for Series input, and Timedelta for scalar input.

For API changes related to the rolling and expanding functions, see detailed overview above.

Other notable API changes:

  • Consistency when indexing with .loc and a list-like indexer when no values are found.

    In [68]: df = DataFrame([['a'],['b']],index=[1,2])
    In [69]: df
    1  a
    2  b

    In prior versions there was a difference in these two constructs:

    • df.loc[[3]] would return a frame reindexed by 3 (with all np.nan values)
    • df.loc[[3],:] would raise KeyError.

    Both will now raise a KeyError. The rule is that at least 1 indexer must be found when using a list-like and .loc (GH7999)

    Furthermore in prior versions these were also different:

    • df.loc[[1,3]] would return a frame reindexed by [1,3]
    • df.loc[[1,3],:] would raise KeyError.

    Both will now return a frame reindex by [1,3]. E.g.

    In [70]: df.loc[[1,3]]
    1    a
    3  NaN
    In [71]: df.loc[[1,3],:]
    1    a
    3  NaN

    This can also be seen in multi-axis indexing with a Panel.

    In [72]: p = Panel(np.arange(2*3*4).reshape(2,3,4),
       ....:           items=['ItemA','ItemB'],
       ....:           major_axis=[1,2,3],
       ....:           minor_axis=['A','B','C','D'])
    In [73]: p
    <class 'pandas.core.panel.Panel'>
    Dimensions: 2 (items) x 3 (major_axis) x 4 (minor_axis)
    Items axis: ItemA to ItemB
    Major_axis axis: 1 to 3
    Minor_axis axis: A to D

    The following would raise KeyError prior to 0.15.0:

    In [74]: p.loc[['ItemA','ItemD'],:,'D']
       ItemA  ItemD
    1      3    NaN
    2      7    NaN
    3     11    NaN

    Furthermore, .loc will raise If no values are found in a multi-index with a list-like indexer:

    In [75]: s = Series(np.arange(3,dtype='int64'),
       ....:            index=MultiIndex.from_product([['A'],['foo','bar','baz']],
       ....:                                          names=['one','two'])
       ....:           ).sortlevel()
    In [76]: s
    one  two
    A    bar    1
         baz    2
         foo    0
    dtype: int64
    In [77]: try:
       ....:    s.loc[['D']]
       ....: except KeyError as e:
       ....:    print("KeyError: " + str(e))
    KeyError: 'cannot index a multi-index axis with these keys'
  • Assigning values to None now considers the dtype when choosing an ‘empty’ value (GH7941).

    Previously, assigning to None in numeric containers changed the dtype to object (or errored, depending on the call). It now uses NaN:

    In [78]: s = Series([1, 2, 3])
    In [79]: s.loc[0] = None
    In [80]: s
    0    NaN
    1    2.0
    2    3.0
    dtype: float64

    NaT is now used similarly for datetime containers.

    For object containers, we now preserve None values (previously these were converted to NaN values).

    In [81]: s = Series(["a", "b", "c"])
    In [82]: s.loc[0] = None
    In [83]: s
    0    None
    1       b
    2       c
    dtype: object

    To insert a NaN, you must explicitly use np.nan. See the docs.

  • In prior versions, updating a pandas object inplace would not reflect in other python references to this object. (GH8511, GH5104)

    In [84]: s = Series([1, 2, 3])
    In [85]: s2 = s
    In [86]: s += 1.5

    Behavior prior to v0.15.0

    # the original object
    In [5]: s
    0    2.5
    1    3.5
    2    4.5
    dtype: float64
    # a reference to the original object
    In [7]: s2
    0    1
    1    2
    2    3
    dtype: int64

    This is now the correct behavior

    # the original object
    In [87]: s
    0    2.5
    1    3.5
    2    4.5
    dtype: float64
    # a reference to the original object
    In [88]: s2
    0    2.5
    1    3.5
    2    4.5
    dtype: float64
  • Made both the C-based and Python engines for read_csv and read_table ignore empty lines in input as well as whitespace-filled lines, as long as sep is not whitespace. This is an API change that can be controlled by the keyword parameter skip_blank_lines. See the docs (GH4466)

  • A timeseries/index localized to UTC when inserted into a Series/DataFrame will preserve the UTC timezone and inserted as object dtype rather than being converted to a naive datetime64[ns] (GH8411).

  • Bug in passing a DatetimeIndex with a timezone that was not being retained in DataFrame construction from a dict (GH7822)

    In prior versions this would drop the timezone, now it retains the timezone, but gives a column of object dtype:

    In [89]: i = date_range('1/1/2011', periods=3, freq='10s', tz = 'US/Eastern')
    In [90]: i
    DatetimeIndex(['2011-01-01 00:00:00-05:00', '2011-01-01 00:00:10-05:00',
                   '2011-01-01 00:00:20-05:00'],
                  dtype='datetime64[ns, US/Eastern]', freq='10S')
    In [91]: df = DataFrame( {'a' : i } )
    In [92]: df
    0 2011-01-01 00:00:00-05:00
    1 2011-01-01 00:00:10-05:00
    2 2011-01-01 00:00:20-05:00
    In [93]: df.dtypes
    a    datetime64[ns, US/Eastern]
    dtype: object

    Previously this would have yielded a column of datetime64 dtype, but without timezone info.

    The behaviour of assigning a column to an existing dataframe as df[‘a’] = i remains unchanged (this already returned an object column with a timezone).

  • When passing multiple levels to stack(), it will now raise a ValueError when the levels aren’t all level names or all level numbers (GH7660). See Reshaping by stacking and unstacking.

  • Raise a ValueError in df.to_hdf with ‘fixed’ format, if df has non-unique columns as the resulting file will be broken (GH7761)

  • SettingWithCopy raise/warnings (according to the option mode.chained_assignment) will now be issued when setting a value on a sliced mixed-dtype DataFrame using chained-assignment. (GH7845, GH7950)

    In [1]: df = DataFrame(np.arange(0,9), columns=['count'])
    In [2]: df['group'] = 'b'
    In [3]: df.iloc[0:5]['group'] = 'a'
    /usr/local/bin/ipython:1: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame.
    Try using .loc[row_indexer,col_indexer] = value instead
    See the the caveats in the documentation:
  • merge, DataFrame.merge, and ordered_merge now return the same type as the left argument (GH7737).

  • Previously an enlargement with a mixed-dtype frame would act unlike .append which will preserve dtypes (related GH2578, GH8176):

    In [94]: df = DataFrame([[True, 1],[False, 2]],
       ....:                columns=["female","fitness"])
    In [95]: df
      female  fitness
    0   True        1
    1  False        2
    In [96]: df.dtypes
    female      bool
    fitness    int64
    dtype: object
    # dtypes are now preserved
    In [97]: df.loc[2] = df.loc[1]
    In [98]: df
      female  fitness
    0   True        1
    1  False        2
    2  False        2
    In [99]: df.dtypes
    female      bool
    fitness    int64
    dtype: object
  • Series.to_csv() now returns a string when path=None, matching the behaviour of DataFrame.to_csv() (GH8215).

  • read_hdf now raises IOError when a file that doesn’t exist is passed in. Previously, a new, empty file was created, and a KeyError raised (GH7715).

  • now ends its output with a newline character (GH8114)

  • Concatenating no objects will now raise a ValueError rather than a bare Exception.

  • Merge errors will now be sub-classes of ValueError rather than raw Exception (GH8501)

  • DataFrame.plot and Series.plot keywords are now have consistent orders (GH8037)

Internal Refactoring

In 0.15.0 Index has internally been refactored to no longer sub-class ndarray but instead subclass PandasObject, similarly to the rest of the pandas objects. This change allows very easy sub-classing and creation of new index types. This should be a transparent change with only very limited API implications (GH5080, GH7439, GH7796, GH8024, GH8367, GH7997, GH8522):

  • you may need to unpickle pandas version < 0.15.0 pickles using pd.read_pickle rather than pickle.load. See pickle docs
  • when plotting with a PeriodIndex, the matplotlib internal axes will now be arrays of Period rather than a PeriodIndex (this is similar to how a DatetimeIndex passes arrays of datetimes now)
  • MultiIndexes will now raise similary to other pandas objects w.r.t. truth testing, see here (GH7897).
  • When plotting a DatetimeIndex directly with matplotlib’s plot function, the axis labels will no longer be formatted as dates but as integers (the internal representation of a datetime64). UPDATE This is fixed in 0.15.1, see here.


  • The attributes Categorical labels and levels attributes are deprecated and renamed to codes and categories.
  • The outtype argument to pd.DataFrame.to_dict has been deprecated in favor of orient. (GH7840)
  • The convert_dummies method has been deprecated in favor of get_dummies (GH8140)
  • The infer_dst argument in tz_localize will be deprecated in favor of ambiguous to allow for more flexibility in dealing with DST transitions. Replace infer_dst=True with ambiguous='infer' for the same behavior (GH7943). See the docs for more details.
  • The top-level pd.value_range has been deprecated and can be replaced by .describe() (GH8481)
  • The Index set operations + and - were deprecated in order to provide these for numeric type operations on certain index types. + can be replaced by .union() or |, and - by .difference(). Further the method name Index.diff() is deprecated and can be replaced by Index.difference() (GH8226)

    # +
    Index(['a','b','c']) + Index(['b','c','d'])
    # should be replaced by
    # -
    Index(['a','b','c']) - Index(['b','c','d'])
    # should be replaced by
  • The infer_types argument to read_html() now has no effect and is deprecated (GH7762, GH7032).

Removal of prior version deprecations/changes

  • Remove DataFrame.delevel method in favor of DataFrame.reset_index


Enhancements in the importing/exporting of Stata files:

  • Added support for bool, uint8, uint16 and uint32 datatypes in to_stata (GH7097, GH7365)
  • Added conversion option when importing Stata files (GH8527)
  • DataFrame.to_stata and StataWriter check string length for compatibility with limitations imposed in dta files where fixed-width strings must contain 244 or fewer characters. Attempting to write Stata dta files with strings longer than 244 characters raises a ValueError. (GH7858)
  • read_stata and StataReader can import missing data information into a DataFrame by setting the argument convert_missing to True. When using this options, missing values are returned as StataMissingValue objects and columns containing missing values have object data type. (GH8045)

Enhancements in the plotting functions:

  • Added layout keyword to DataFrame.plot. You can pass a tuple of (rows, columns), one of which can be -1 to automatically infer (GH6667, GH8071).
  • Allow to pass multiple axes to DataFrame.plot, hist and boxplot (GH5353, GH6970, GH7069)
  • Added support for c, colormap and colorbar arguments for DataFrame.plot with kind='scatter' (GH7780)
  • Histogram from DataFrame.plot with kind='hist' (GH7809), See the docs.
  • Boxplot from DataFrame.plot with kind='box' (GH7998), See the docs.


  • read_csv now has a keyword parameter float_precision which specifies which floating-point converter the C engine should use during parsing, see here (GH8002, GH8044)

  • Added searchsorted method to Series objects (GH7447)

  • describe() on mixed-types DataFrames is more flexible. Type-based column filtering is now possible via the include/exclude arguments. See the docs (GH8164).

    In [100]: df = DataFrame({'catA': ['foo', 'foo', 'bar'] * 8,
       .....:                 'catB': ['a', 'b', 'c', 'd'] * 6,
       .....:                 'numC': np.arange(24),
       .....:                 'numD': np.arange(24.) + .5})
    In [101]: df.describe(include=["object"])
           catA catB
    count    24   24
    unique    2    4
    top     foo    d
    freq     16    6
    In [102]: df.describe(include=["number", "object"], exclude=["float"])
           catA catB       numC
    count    24   24  24.000000
    unique    2    4        NaN
    top     foo    d        NaN
    freq     16    6        NaN
    mean    NaN  NaN  11.500000
    std     NaN  NaN   7.071068
    min     NaN  NaN   0.000000
    25%     NaN  NaN   5.750000
    50%     NaN  NaN  11.500000
    75%     NaN  NaN  17.250000
    max     NaN  NaN  23.000000

    Requesting all columns is possible with the shorthand ‘all’

    In [103]: df.describe(include='all')
           catA catB       numC       numD
    count    24   24  24.000000  24.000000
    unique    2    4        NaN        NaN
    top     foo    d        NaN        NaN
    freq     16    6        NaN        NaN
    mean    NaN  NaN  11.500000  12.000000
    std     NaN  NaN   7.071068   7.071068
    min     NaN  NaN   0.000000   0.500000
    25%     NaN  NaN   5.750000   6.250000
    50%     NaN  NaN  11.500000  12.000000
    75%     NaN  NaN  17.250000  17.750000
    max     NaN  NaN  23.000000  23.500000

    Without those arguments, ‘describe` will behave as before, including only numerical columns or, if none are, only categorical columns. See also the docs

  • Added split as an option to the orient argument in pd.DataFrame.to_dict. (GH7840)

  • The get_dummies method can now be used on DataFrames. By default only catagorical columns are encoded as 0’s and 1’s, while other columns are left untouched.

    In [104]: df = DataFrame({'A': ['a', 'b', 'a'], 'B': ['c', 'c', 'b'],
       .....:                 'C': [1, 2, 3]})
    In [105]: pd.get_dummies(df)
       C  A_a  A_b  B_b  B_c
    0  1  1.0  0.0  0.0  1.0
    1  2  0.0  1.0  0.0  1.0
    2  3  1.0  0.0  1.0  0.0
  • PeriodIndex supports resolution as the same as DatetimeIndex (GH7708)

  • has added support for additional holidays and ways to observe holidays (GH7070)

  • now supports a list of offsets in Python3 (GH7070)

  • now supports a days_of_week parameter (GH7070)

  • GroupBy.nth() now supports selecting multiple nth values (GH7910)

    In [106]: business_dates = date_range(start='4/1/2014', end='6/30/2014', freq='B')
    In [107]: df = DataFrame(1, index=business_dates, columns=['a', 'b'])
    # get the first, 4th, and last date index for each month
    In [108]: df.groupby((df.index.year, df.index.month)).nth([0, 3, -1])
            a  b
    2014 4  1  1
         4  1  1
         4  1  1
         5  1  1
         5  1  1
         5  1  1
         6  1  1
         6  1  1
         6  1  1
  • Period and PeriodIndex supports addition/subtraction with timedelta-likes (GH7966)

    If Period freq is D, H, T, S, L, U, N, Timedelta-like can be added if the result can have same freq. Otherwise, only the same offsets can be added.

    In [109]: idx = pd.period_range('2014-07-01 09:00', periods=5, freq='H')
    In [110]: idx
    PeriodIndex(['2014-07-01 09:00', '2014-07-01 10:00', '2014-07-01 11:00',
                 '2014-07-01 12:00', '2014-07-01 13:00'],
                dtype='int64', freq='H')
    In [111]: idx + pd.offsets.Hour(2)
    PeriodIndex(['2014-07-01 11:00', '2014-07-01 12:00', '2014-07-01 13:00',
                 '2014-07-01 14:00', '2014-07-01 15:00'],
                dtype='int64', freq='H')
    In [112]: idx + Timedelta('120m')
    PeriodIndex(['2014-07-01 11:00', '2014-07-01 12:00', '2014-07-01 13:00',
                 '2014-07-01 14:00', '2014-07-01 15:00'],
                dtype='int64', freq='H')
    In [113]: idx = pd.period_range('2014-07', periods=5, freq='M')
    In [114]: idx
    Out[114]: PeriodIndex(['2014-07', '2014-08', '2014-09', '2014-10', '2014-11'], dtype='int64', freq='M')
    In [115]: idx + pd.offsets.MonthEnd(3)
    Out[115]: PeriodIndex(['2014-10', '2014-11', '2014-12', '2015-01', '2015-02'], dtype='int64', freq='M')
  • Added experimental compatibility with openpyxl for versions >= 2.0. The DataFrame.to_excel method engine keyword now recognizes openpyxl1 and openpyxl2 which will explicitly require openpyxl v1 and v2 respectively, failing if the requested version is not available. The openpyxl engine is a now a meta-engine that automatically uses whichever version of openpyxl is installed. (GH7177)

  • DataFrame.fillna can now accept a DataFrame as a fill value (GH8377)

  • Passing multiple levels to stack() will now work when multiple level numbers are passed (GH7660). See Reshaping by stacking and unstacking.

  • set_names(), set_labels(), and set_levels() methods now take an optional level keyword argument to all modification of specific level(s) of a MultiIndex. Additionally set_names() now accepts a scalar string value when operating on an Index or on a specific level of a MultiIndex (GH7792)

    In [116]: idx = MultiIndex.from_product([['a'], range(3), list("pqr")], names=['foo', 'bar', 'baz'])
    In [117]: idx.set_names('qux', level=0)
    MultiIndex(levels=[[u'a'], [0, 1, 2], [u'p', u'q', u'r']],
               labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]],
               names=[u'qux', u'bar', u'baz'])
    In [118]: idx.set_names(['qux','baz'], level=[0,1])
    MultiIndex(levels=[[u'a'], [0, 1, 2], [u'p', u'q', u'r']],
               labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]],
               names=[u'qux', u'baz', u'baz'])
    In [119]: idx.set_levels(['a','b','c'], level='bar')
    MultiIndex(levels=[[u'a'], [u'a', u'b', u'c'], [u'p', u'q', u'r']],
               labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]],
               names=[u'foo', u'bar', u'baz'])
    In [120]: idx.set_levels([['a','b','c'],[1,2,3]], level=[1,2])
    MultiIndex(levels=[[u'a'], [u'a', u'b', u'c'], [1, 2, 3]],
               labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]],
               names=[u'foo', u'bar', u'baz'])
  • Index.isin now supports a level argument to specify which index level to use for membership tests (GH7892, GH7890)

    In [1]: idx = MultiIndex.from_product([[0, 1], ['a', 'b', 'c']])
    In [2]: idx.values
    Out[2]: array([(0, 'a'), (0, 'b'), (0, 'c'), (1, 'a'), (1, 'b'), (1, 'c')], dtype=object)
    In [3]: idx.isin(['a', 'c', 'e'], level=1)
    Out[3]: array([ True, False,  True,  True, False,  True], dtype=bool)
  • Index now supports duplicated and drop_duplicates. (GH4060)

    In [121]: idx = Index([1, 2, 3, 4, 1, 2])
    In [122]: idx
    Out[122]: Int64Index([1, 2, 3, 4, 1, 2], dtype='int64')
    In [123]: idx.duplicated()
    Out[123]: array([False, False, False, False,  True,  True], dtype=bool)
    In [124]: idx.drop_duplicates()
    Out[124]: Int64Index([1, 2, 3, 4], dtype='int64')
  • add copy=True argument to pd.concat to enable pass thru of complete blocks (GH8252)

  • Added support for numpy 1.8+ data types (bool_, int_, float_, string_) for conversion to R dataframe (GH8400)


  • Performance improvements in DatetimeIndex.__iter__ to allow faster iteration (GH7683)
  • Performance improvements in Period creation (and PeriodIndex setitem) (GH5155)
  • Improvements in Series.transform for significant performance gains (revised) (GH6496)
  • Performance improvements in StataReader when reading large files (GH8040, GH8073)
  • Performance improvements in StataWriter when writing large files (GH8079)
  • Performance and memory usage improvements in multi-key groupby (GH8128)
  • Performance improvements in groupby .agg and .apply where builtins max/min were not mapped to numpy/cythonized versions (GH7722)
  • Performance improvement in writing to sql (to_sql) of up to 50% (GH8208).
  • Performance benchmarking of groupby for large value of ngroups (GH6787)
  • Performance improvement in CustomBusinessDay, CustomBusinessMonth (GH8236)
  • Performance improvement for MultiIndex.values for multi-level indexes containing datetimes (GH8543)

Bug Fixes

  • Bug in pivot_table, when using margins and a dict aggfunc (GH8349)
  • Bug in read_csv where squeeze=True would return a view (GH8217)
  • Bug in checking of table name in read_sql in certain cases (GH7826).
  • Bug in DataFrame.groupby where Grouper does not recognize level when frequency is specified (GH7885)
  • Bug in multiindexes dtypes getting mixed up when DataFrame is saved to SQL table (GH8021)
  • Bug in Series 0-division with a float and integer operand dtypes (GH7785)
  • Bug in Series.astype("unicode") not calling unicode on the values correctly (GH7758)
  • Bug in DataFrame.as_matrix() with mixed datetime64[ns] and timedelta64[ns] dtypes (GH7778)
  • Bug in HDFStore.select_column() not preserving UTC timezone info when selecting a DatetimeIndex (GH7777)
  • Bug in to_datetime when format='%Y%m%d' and coerce=True are specified, where previously an object array was returned (rather than a coerced time-series with NaT), (GH7930)
  • Bug in DatetimeIndex and PeriodIndex in-place addition and subtraction cause different result from normal one (GH6527)
  • Bug in adding and subtracting PeriodIndex with PeriodIndex raise TypeError (GH7741)
  • Bug in combine_first with PeriodIndex data raises TypeError (GH3367)
  • Bug in multi-index slicing with missing indexers (GH7866)
  • Bug in multi-index slicing with various edge cases (GH8132)
  • Regression in multi-index indexing with a non-scalar type object (GH7914)
  • Bug in Timestamp comparisons with == and int64 dtype (GH8058)
  • Bug in pickles contains DateOffset may raise AttributeError when normalize attribute is reffered internally (GH7748)
  • Bug in Panel when using major_xs and copy=False is passed (deprecation warning fails because of missing warnings) (GH8152).
  • Bug in pickle deserialization that failed for pre-0.14.1 containers with dup items trying to avoid ambiguity when matching block and manager items, when there’s only one block there’s no ambiguity (GH7794)
  • Bug in putting a PeriodIndex into a Series would convert to int64 dtype, rather than object of Periods (GH7932)
  • Bug in HDFStore iteration when passing a where (GH8014)
  • Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (GH8046, GH8430)
  • Bug in repeated timeseries line and area plot may result in ValueError or incorrect kind (GH7733)
  • Bug in inference in a MultiIndex with inputs (GH7888)
  • Bug in get where an IndexError would not cause the default value to be returned (GH7725)
  • Bug in offsets.apply, rollforward and rollback may reset nanosecond (GH7697)
  • Bug in offsets.apply, rollforward and rollback may raise AttributeError if Timestamp has dateutil tzinfo (GH7697)
  • Bug in sorting a multi-index frame with a Float64Index (GH8017)
  • Bug in inconsistent panel setitem with a rhs of a DataFrame for alignment (GH7763)
  • Bug in is_superperiod and is_subperiod cannot handle higher frequencies than S (GH7760, GH7772, GH7803)
  • Bug in 32-bit platforms with Series.shift (GH8129)
  • Bug in PeriodIndex.unique returns int64 np.ndarray (GH7540)
  • Bug in groupby.apply with a non-affecting mutation in the function (GH8467)
  • Bug in DataFrame.reset_index which has MultiIndex contains PeriodIndex or DatetimeIndex with tz raises ValueError (GH7746, GH7793)
  • Bug in DataFrame.plot with subplots=True may draw unnecessary minor xticks and yticks (GH7801)
  • Bug in StataReader which did not read variable labels in 117 files due to difference between Stata documentation and implementation (GH7816)
  • Bug in StataReader where strings were always converted to 244 characters-fixed width irrespective of underlying string size (GH7858)
  • Bug in DataFrame.plot and Series.plot may ignore rot and fontsize keywords (GH7844)
  • Bug in DatetimeIndex.value_counts doesn’t preserve tz (GH7735)
  • Bug in PeriodIndex.value_counts results in Int64Index (GH7735)
  • Bug in DataFrame.join when doing left join on index and there are multiple matches (GH5391)
  • Bug in GroupBy.transform() where int groups with a transform that didn’t preserve the index were incorrectly truncated (GH7972).
  • Bug in groupby where callable objects without name attributes would take the wrong path, and produce a DataFrame instead of a Series (GH7929)
  • Bug in groupby error message when a DataFrame grouping column is duplicated (GH7511)
  • Bug in read_html where the infer_types argument forced coercion of date-likes incorrectly (GH7762, GH7032).
  • Bug in with an index which was filtered as to not include the first item (GH7857)
  • Bug in Timestamp cannot parse nanosecond from string (GH7878)
  • Bug in Timestamp with string offset and tz results incorrect (GH7833)
  • Bug in tslib.tz_convert and tslib.tz_convert_single may return different results (GH7798)
  • Bug in DatetimeIndex.intersection of non-overlapping timestamps with tz raises IndexError (GH7880)
  • Bug in alignment with TimeOps and non-unique indexes (GH8363)
  • Bug in GroupBy.filter() where fast path vs. slow path made the filter return a non scalar value that appeared valid but wasn’t (GH7870).
  • Bug in date_range()/DatetimeIndex() when the timezone was inferred from input dates yet incorrect times were returned when crossing DST boundaries (GH7835, GH7901).
  • Bug in to_excel() where a negative sign was being prepended to positive infinity and was absent for negative infinity (GH7949)
  • Bug in area plot draws legend with incorrect alpha when stacked=True (GH8027)
  • Period and PeriodIndex addition/subtraction with np.timedelta64 results in incorrect internal representations (GH7740)
  • Bug in Holiday with no offset or observance (