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.
Highlights include:
The Categorical type was integrated as a first-class pandas type, see here
In [1]: df=pd.DataFrame({"id":[1,2,3,4,5,6], ...: "raw_grade":['a','b','b','a','a','e'
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 Categorical.codes and is read
only. If you want to manipulate codes, please use one of the
.
TimedeltaIndex/scalar
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.
(GH 3009, GH 4533, GH 8209, GH 8187, GH 8190, GH 7869, , , )
Memory usage
Implemented methods to find memory usage of a DataFrame. See the FAQ for more. (GH 6852).
A new display option display.memory_usage (see Options and settings) sets the default behavior of the memory_usage argument in the df.info() method. By default display.memory_usage is True.
In [30]: dtypes=[
Series.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. (GH 7207)
This will return a Series, indexed like the existing Series. See the docs
# datetimeIn [37]: s=pd.Series(pd.date_range('20130101 09:10:12',periods=4))In [38]: s
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 (GH 7812)
In [58]: ts=pd.Timestamp('2014-08-01 09:00',
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). (GH 7766)
Prior to 0.15.0
In [57]: s
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 (GH 8062).
Added support for a chunksize parameter to read_sql function. Specifying this argument will return an iterator through chunks of the query result (GH 2908).
Added support for writing datetime.date and datetime.time object columns with to_sql (GH 6932).
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'])Out[2]:[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 [61]: df=pd.DataFrame([['a'],['b']],index=[1,2])In [62]: dfOut[62]: 01 a2 b[2 rows x 1 columns]
Made both the C-based and Python engines for read_csv and read_table ignore empty lines in input as well as
white space-filled lines, as long as sep is not white space. This is an API change
that can be controlled by the keyword parameter skip_blank_lines. See the docs (GH 4466)
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] (GH 8411).
Bug in passing a DatetimeIndex with a timezone that was not being retained in DataFrame construction from a dict ()
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 (GH 5080, GH 7439, GH 7796, GH 8024, GH 8367, GH 7997, GH 8522):
you may need to unpickle pandas version < 0.15.0 pickles using pd.read_pickle rather than . See
Deprecations
The attributes Categoricallabels 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. (GH 7840)
The convert_dummies method has been deprecated in favor of
()
Removal of prior version deprecations/changes
Remove DataFrame.delevel method in favor of DataFrame.reset_index
Enhancements
Enhancements in the importing/exporting of Stata files:
Added support for bool, uint8, uint16 and uint32 data types in to_stata (GH 7097, GH 7365)
Added conversion option when importing Stata files (GH 8527)
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. (GH 7858)
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. (GH 8045)
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 (GH 6667, GH 8071).
Allow to pass multiple axes to DataFrame.plot, hist and boxplot (GH 5353, GH 6970, GH 7069)
Added support for , and arguments for with ()
Other:
read_csv now has a keyword parameter float_precision which specifies which floating-point converter the C engine should use during parsing, see here (GH 8002, GH 8044)
Added searchsorted method to Series objects (GH 7447)
describe() on mixed-types DataFrames is more flexible. Type-based column filtering is now possible via the include/exclude arguments.
See the ().
Performance
Performance improvements in DatetimeIndex.__iter__ to allow faster iteration (GH 7683)
Performance improvements in Period creation (and PeriodIndex setitem) (GH 5155)
Improvements in Series.transform for significant performance gains (revised) (GH 6496)
Performance improvements in StataReader when reading large files (GH 8040, GH 8073)
Performance improvements in StataWriter when writing large files (GH 8079)
Performance and memory usage improvements in multi-key groupby (GH 8128)
Performance improvements in groupby .agg and .apply where builtins max/min were not mapped to numpy/cythonized versions (GH 7722)
Performance improvement in writing to sql (to_sql) of up to 50% (GH 8208).
Performance benchmarking of groupby for large value of ngroups (GH 6787)
Performance improvement in CustomBusinessDay, CustomBusinessMonth (GH 8236)
Performance improvement for MultiIndex.values for multi-level indexes containing datetimes (GH 8543)
Bug fixes
Bug in pivot_table, when using margins and a dict aggfunc (GH 8349)
Bug in read_csv where squeeze=True would return a view (GH 8217)
Bug in checking of table name in read_sql in certain cases (GH 7826).
Bug in DataFrame.groupby where Grouper does not recognize level when frequency is specified (GH 7885)
Bug in multiindexes dtypes getting mixed up when DataFrame is saved to SQL table (GH 8021)
Bug in Series 0-division with a float and integer operand dtypes (GH 7785)
Bug in Series.astype("unicode") not calling unicode on the values correctly (GH 7758)
Bug in DataFrame.as_matrix() with mixed datetime64[ns] and timedelta64[ns] dtypes (GH 7778)
Bug in HDFStore.select_column() not preserving UTC timezone info when selecting a DatetimeIndex (GH 7777)
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), (GH 7930)
Bug in DatetimeIndex and PeriodIndex in-place addition and subtraction cause different result from normal one (GH 6527)
Bug in adding and subtracting PeriodIndex with PeriodIndex raise TypeError (GH 7741)
Bug in combine_first with PeriodIndex data raises TypeError (GH 3367)
Bug in MultiIndex slicing with missing indexers (GH 7866)
Bug in MultiIndex slicing with various edge cases (GH 8132)
Regression in MultiIndex indexing with a non-scalar type object (GH 7914)
Bug in Timestamp comparisons with == and int64 dtype (GH 8058)
Bug in pickles contains DateOffset may raise AttributeError when normalize attribute is referred internally (GH 7748)
Bug in Panel when using major_xs and copy=False is passed (deprecation warning fails because of missing warnings) (GH 8152).
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 (GH 7794)
Bug in putting a PeriodIndex into a Series would convert to int64 dtype, rather than object of Periods (GH 7932)
Bug in HDFStore iteration when passing a where (GH 8014)
Bug in DataFrameGroupby.transform when transforming with a passed non-sorted key (GH 8046, GH 8430)
Bug in repeated timeseries line and area plot may result in ValueError or incorrect kind (GH 7733)
Bug in inference in a MultiIndex with datetime.date inputs (GH 7888)
Bug in get where an IndexError would not cause the default value to be returned (GH 7725)
Bug in offsets.apply, rollforward and rollback may reset nanosecond (GH 7697)
Bug in offsets.apply, rollforward and rollback may raise AttributeError if Timestamp has dateutil tzinfo (GH 7697)
Bug in sorting a MultiIndex frame with a Float64Index (GH 8017)
Bug in inconsistent panel setitem with a rhs of a DataFrame for alignment (GH 7763)
Bug in is_superperiod and is_subperiod cannot handle higher frequencies than S (GH 7760, GH 7772, GH 7803)
Bug in 32-bit platforms with Series.shift (GH 8129)
Bug in PeriodIndex.unique returns int64 np.ndarray (GH 7540)
Bug in groupby.apply with a non-affecting mutation in the function (GH 8467)
Bug in DataFrame.reset_index which has MultiIndex contains PeriodIndex or DatetimeIndex with tz raises ValueError (GH 7746, GH 7793)
Bug in DataFrame.plot with subplots=True may draw unnecessary minor xticks and yticks (GH 7801)
Bug in StataReader which did not read variable labels in 117 files due to difference between Stata documentation and implementation (GH 7816)
Bug in StataReader where strings were always converted to 244 characters-fixed width irrespective of underlying string size (GH 7858)
Bug in DataFrame.plot and Series.plot may ignore rot and fontsize keywords (GH 7844)
Bug in DatetimeIndex.value_counts doesn’t preserve tz (GH 7735)
Bug in PeriodIndex.value_counts results in Int64Index (GH 7735)
Bug in DataFrame.join when doing left join on index and there are multiple matches (GH 5391)
Bug in GroupBy.transform() where int groups with a transform that
didn’t preserve the index were incorrectly truncated (GH 7972).
Bug in groupby where callable objects without name attributes would take the wrong path,
and produce a DataFrame instead of a Series (GH 7929)
Bug in groupby error message when a DataFrame grouping column is duplicated (GH 7511)
Bug in read_html where the infer_types argument forced coercion of
date-likes incorrectly (GH 7762, GH 7032).
Bug in Series.str.cat with an index which was filtered as to not include the first item (GH 7857)
Bug in Timestamp cannot parse nanosecond from string (GH 7878)
Bug in Timestamp with string offset and tz results incorrect (GH 7833)
Bug in tslib.tz_convert and tslib.tz_convert_single may return different results (GH 7798)
Bug in DatetimeIndex.intersection of non-overlapping timestamps with tz raises IndexError (GH 7880)
Bug in alignment with TimeOps and non-unique indexes (GH 8363)
Bug in GroupBy.filter() where fast path vs. slow path made the filter
return a non scalar value that appeared valid but wasn’t (GH 7870).
Bug in date_range()/DatetimeIndex() when the timezone was inferred from input dates yet incorrect
times were returned when crossing DST boundaries (GH 7835, GH 7901).
Bug in to_excel() where a negative sign was being prepended to positive infinity and was absent for negative infinity (GH 7949)
Bug in area plot draws legend with incorrect alpha when stacked=True (GH 8027)
Period and PeriodIndex addition/subtraction with np.timedelta64 results in incorrect internal representations (GH 7740)
Bug in Holiday with no offset or observance (GH 7987)
Bug in DataFrame.to_latex formatting when columns or index is a MultiIndex (GH 7982).
Bug in DateOffset around Daylight Savings Time produces unexpected results (GH 5175).
Bug in DataFrame.shift where empty columns would throw ZeroDivisionError on numpy 1.7 (GH 8019)
Bug in installation where html_encoding/*.html wasn’t installed and
therefore some tests were not running correctly (GH 7927).
Bug in read_html where bytes objects were not tested for in
_read (GH 7927).
Bug in DataFrame.stack() when one of the column levels was a datelike (GH 8039)
Bug in broadcasting numpy scalars with DataFrame (GH 8116)
Bug in pivot_table performed with nameless index and columns raises KeyError (GH 8103)
Bug in DataFrame.plot(kind='scatter') draws points and errorbars with different colors when the color is specified by c keyword (GH 8081)
Bug in Float64Index where iat and at were not testing and were
failing (GH 8092).
Bug in DataFrame.boxplot() where y-limits were not set correctly when
producing multiple axes (GH 7528, GH 5517).
Bug in read_csv where line comments were not handled correctly given
a custom line terminator or delim_whitespace=True (GH 8122).
Bug in read_html where empty tables caused a StopIteration (GH 7575)
Bug in casting when setting a column in a same-dtype block (GH 7704)
Bug in accessing groups from a GroupBy when the original grouper
was a tuple (GH 8121).
Bug in .at that would accept integer indexers on a non-integer index and do fallback (GH 7814)
In [9]: pd.Timedelta('1 days 06:05:01.00003')Out[9]: Timedelta('1 days 06:05:01.000030')In [10]: pd.Timedelta('15.5us')Out[10]: Timedelta('0 days 00:00:00.000015500')In [11]: pd.Timedelta('1 hour 15.5us')Out[11]: Timedelta('0 days 01:00:00.000015500')# negative Timedeltas have this string repr# to be more consistent with datetime.timedelta conventionsIn [12]: pd.Timedelta('-1us')Out[12]: Timedelta('-1 days +23:59:59.999999')# a NaTIn [13]: pd.Timedelta('nan')Out[13]: NaT
In[20]:pd.timedelta_range(start='1 days',end='2 days',freq='30T')Out[20]: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 [20]: s=pd.Series(np.arange(5), ....: index=pd.timedelta_range('1 days',periods=5,freq='s')) ....: In [21]: sOut[21]: 1 days 00:00:00 01 days 00:00:01 11 days 00:00:02 21 days 00:00:03 31 days 00:00:04 4Freq: s, Length: 5, dtype: int64
You can select with partial string selections
In [22]: s['1 day 00:00:02']Out[22]: 2In [23]: s['1 day':'1 day 00:00:02']Out[23]: 1 days 00:00:00 01 days 00:00:01 11 days 00:00:02 2Freq: s, Length: 3, dtype: int64
Finally, the combination of TimedeltaIndex with DatetimeIndex allow certain combination operations that are NaT preserving:
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.
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 (GH 7943)
DataFrame.tz_localize and DataFrame.tz_convert now accepts an optional level argument
for localizing a specific level of a MultiIndex (GH 7846)
Timestamp.tz_localize and Timestamp.tz_convert now raise TypeError in error cases, rather than Exception (GH 8025)
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 (GH 8411)
Timestamp.__repr__ displays dateutil.tz.tzoffset info (GH 7907)
=
pd
.
Series
([
10
,
11
,
12
,
13
])
In [15]: pd.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)Out[4]:0 NaN1 NaN2 NaN3 NaNdtype: 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)/2NaN values (or with shrinking windows, in the case of rolling_apply()).
(GH 7925, GH 8269)
Prior behavior (note final value is NaN):
In [7]: pd.rolling_sum(Series(range(4)),window=3,min_periods=0,center=True)Out[7]:0 11 32 63 NaNdtype: float64
New behavior (note final value is 5=sum([2,3,NaN])):
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. (GH 7618)
In [58]: s=pd.Series([10.5,8.8,11.4,9.7,9.3])
Behavior prior to 0.15.0:
In [39]: pd.rolling_window(s,window=3,win_type='triang',center=True)Out[39]:0 NaN1 6.5833332 6.8833333 6.6833334 NaNdtype: float64
New behavior
In [10]: pd.rolling_window(s,window=3,win_type='triang',center=True)Out[10]:0 NaN1 9.8752 10.3253 10.0254 NaNdtype: float64
Removed center argument from all expanding_ functions (see list),
as the results produced when center=True did not make much sense. (GH 7925)
Added optional ddof argument to expanding_cov() and rolling_cov().
The default value of 1 is backwards-compatible. (GH 8279)
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. (GH 8064)
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. (GH 7977)
Prior behavior (note values start at index 2, which is min_periods after index 0
(the index of the first non-empty value)):
In [59]: s=pd.Series([1,None,None,None,2,3])
In [51]: pd.ewma(s,com=3.,min_periods=2)Out[51]:0 NaN1 NaN2 1.0000003 1.0000004 1.5714295 2.189189dtype: 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)Out[2]:0 NaN1 NaN2 NaN3 NaN4 1.7596445 2.383784dtype: 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. (GH 7911)
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.
(GH 7543)
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) (GH 7542)
Bug in rolling_count() and expanding_*() functions unnecessarily producing error message for zero-length data (GH 8056)
Bug in rolling_apply() and expanding_apply() interpreting min_periods=0 as min_periods=1 (GH 8080)
Bug in expanding_std() and expanding_var() for a single value producing a confusing error message (GH 7900)
Bug in rolling_std() and rolling_var() for a single value producing 0 rather than NaN (GH 7900)
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 [60]: s=pd.Series([1.,2.,0.,4.])
In [89]: pd.ewmvar(s,com=2.,bias=False)Out[89]:0 -2.775558e-161 3.000000e-012 9.556787e-013 3.585799e+00dtype: float64In [90]: pd.ewmvar(s,com=2.,bias=
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)Out[14]:0 NaN1 0.5000002 1.2105263 4.089069dtype: float64In [15]: pd.ewmvar(s,com=2.,bias
Added support for writing NaN values with to_sql (GH 2754).
Added support for writing datetime64 columns with to_sql for all database flavors (GH 7103).
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 (GH 7999)
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 [3]: df.loc[[1,3]]Out[3]: 01 a3 NaNIn [4]: df.loc[[1,3],:]Out[4]: 01 a3 NaN
This can also be seen in multi-axis indexing with a Panel.
>>> p=pd.Panel(np.arange(2*3*4).reshape(2,3,4),... items=['ItemA','ItemB'],... major_axis=[1,2,3],... minor_axis=['A','B','C','D'])>>> p<class 'pandas.core.panel.Panel'>Dimensions: 2 (items) x 3 (major_axis) x 4 (minor_axis)Items axis: ItemA to ItemBMajor_axis axis: 1 to 3Minor_axis axis: A to D
The following would raise KeyError prior to 0.15.0:
In [5]:Out[5]: ItemA ItemD1 3 NaN2 7 NaN3 11 NaN
Furthermore, .loc will raise If no values are found in a MultiIndex with a list-like indexer:
In [63]: s=pd.Series(np.arange(3,dtype='int64'), ....: index=pd.MultiIndex.from_product([['A'], ....: ['foo','bar','baz']], ....: names=['one','two']) ....: ).sort_index() ....: In [64]: sOut[64]: one twoA bar 1 baz 2 foo 0Length: 3, dtype: int64In [65]: try: ....: s.loc[['D']] ....: exceptKeyErrorase: ....: print("KeyError: "+str(e)) ....: KeyError: "['D'] not in index"
Assigning values to None now considers the dtype when choosing an ‘empty’ value (GH 7941).
Previously, assigning to None in numeric containers changed the
dtype to object (or errored, depending on the call). It now uses
NaN:
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. (GH 8511, GH 5104)
In [72]: s=pd.Series([1,2,3])In [73]: s2=sIn [74]: s+=1.5
Behavior prior to v0.15.0
# the original objectIn [5]: sOut[5]:0 2.51 3.52 4.5dtype: float64# a reference to the original objectIn [7]: s2Out[7]:0 11 22 3dtype: int64
This is now the correct behavior
# the original objectIn [75]: sOut[75]: 0 2.51 3.52 4.5Length: 3, dtype: float64# a reference to the original objectIn [76]: s2Out[76]: 0 2.51 3.52 4.5Length: 3, dtype: float64
Raise a ValueError in df.to_hdf with ‘fixed’ format, if df has non-unique columns as the resulting file will be broken (GH 7761)
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. (GH 7845, GH 7950)
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 similarly to other pandas objects w.r.t. truth testing, see here (GH 7897).
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 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 (GH 7943).
See the docs for more details.
The top-level pd.value_range has been deprecated and can be replaced by .describe() (GH 8481)
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() (GH 8226)
# +pd.Index(['a','b','c'])+pd.Index(['b','c','d'])# should be replaced bypd.Index(['a','b','c']).union(pd.
# -pd.Index(['a','b','c'])-pd.Index(['b','c','d'])# should be replaced bypd.Index(['a','b','c']).difference(
In [88]: df=pd.DataFrame({'catA':['foo','foo','bar']*8, ....: 'catB':['a','b','c','d']*6, ....: 'numC':np.arange(24), ....: 'numD':np.arange(24.)+.5}) ....: In [89]: df.describe(include=["object"])Out[89]: catA catBcount 24 24unique 2 4top foo afreq 16 6[4 rows x 2 columns]In [90]: df.describe(include=["number","object"],exclude=["float"])Out[90]: catA catB numCcount 24 24 24.000000unique 2 4 NaNtop foo a NaNfreq 16 6 NaNmean NaN NaN 11.500000std NaN NaN 7.071068min NaN NaN 0.00000025% NaN NaN 5.75000050% NaN NaN 11.50000075% NaN NaN 17.250000max NaN NaN 23.000000[11 rows x 3 columns]
Requesting all columns is possible with the shorthand ‘all’
In [91]: df.describe(include='all')Out[91]: catA catB numC numDcount 24 24 24.000000 24.000000unique 2 4 NaN NaNtop foo a NaN NaNfreq 16 6 NaN NaNmean NaN NaN 11.500000 12.000000std NaN NaN 7.071068 7.071068min NaN NaN 0.000000 0.50000025% NaN NaN 5.750000 6.25000050% NaN NaN 11.500000 12.00000075% NaN NaN 17.250000 17.750000max NaN NaN 23.000000 23.500000[11 rows x 4 columns]
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. (GH 7840)
The get_dummies method can now be used on DataFrames. By default only
categorical columns are encoded as 0’s and 1’s, while other columns are
left untouched.
In [92]: df=pd.DataFrame({'A':['a','b','a'],'B':['c','c','b'], ....: 'C':[1,2,3]}) ....: In [93]: pd.get_dummies(df)Out[93]: C A_a A_b B_b B_c0 1 True False False True1 2 False True False True2 3 True False True False[3 rows x 5 columns]
PeriodIndex supports resolution as the same as DatetimeIndex (GH 7708)
pandas.tseries.holiday has added support for additional holidays and ways to observe holidays (GH 7070)
pandas.tseries.holiday.Holiday now supports a list of offsets in Python3 (GH 7070)
pandas.tseries.holiday.Holiday now supports a days_of_week parameter (GH 7070)
GroupBy.nth() now supports selecting multiple nth values (GH 7910)
In [94]: business_dates=pd.date_range(start='4/1/2014',end='6/30/2014',freq='B')In [95]: df=pd.DataFrame(1,index=business_dates,columns=['a','b'])# get the first, 4th, and last date index for each monthIn [96]: df.groupby([df.index.year,df.index.month]).nth([0,3,-1])Out[96]: a b2014-04-01 1 12014-04-04 1 12014-04-30 1 12014-05-01 1 12014-05-06 1 12014-05-30 1 12014-06-02 1 12014-06-05 1 12014-06-30 1 1[9 rows x 2 columns]
Period and PeriodIndex supports addition/subtraction with timedelta-likes (GH 7966)
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.
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. (GH 7177)
DataFrame.fillna can now accept a DataFrame as a fill value (GH 8377)
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 (GH 7792)