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.
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 (GH 11603, GH 12373)
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 DataFrame.rolling(window=3,center=False).mean()Out[8]: A B0 NaN NaN1 NaN NaN2 1 0.2377223 2 -0.0236404 3 0.1331555 4 -0.0486936 5 0.3420547 6 0.3700768 7 0.0795879 8 -0.954504
New behavior:
In [4]: r=df.rolling(window=3)
These show a descriptive repr
In [5]: rOut[5]: Rolling [window=3,center=False,axis=0,method=single]
with tab-completion of available methods and properties.
In [6]: r.mean()Out[6]: A B0 NaN NaN1 NaN NaN2 1.0 0.2377223 2.0 -0.0236404 3.0 0.1331555 4.0 -0.0486936 5.0 0.3420547 6.0 0.3700768 7.0 0.0795879 8.0 -0.954504[10 rows x 2 columns]
They provide getitem accessors
In [7]: r['A'].mean()Out[7]: 0 NaN1 NaN2 1.03 2.04 3.05 4.06 5.07 6.08 7.09 8.0Name: A, Length: 10, dtype: float64
And multiple aggregations
In [8]: r.agg({'A':['mean','std'], ...: 'B':['mean','std']}) ...: Out[8]: A B mean std mean std0 NaN NaN NaN NaN1 NaN NaN NaN NaN2 1.0 1.0 0.237722 1.3273643 2.0 1.0 -0.023640 1.3355054 3.0 1.0 0.133155 1.1437785 4.0 1.0 -0.048693 0.8357476 5.0 1.0 0.342054 0.9203797 6.0 1.0 0.370076 0.871850
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. (GH 9494, GH 11965)
In [9]: s=pd.Series(np.random.randn(5))In [10]: s.
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. (GH 939, GH 12070, GH 12071, GH 12109, )
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
(GH 11386).
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 , which is more consistent and less confusing from the perspective of a user.
Addition of str.extractall
The .str.extractall method was added
(GH 11386). Unlike extract, which returns only the first
match.
In [23]: s=pd.Series(["a1a2","b1","c1"],["A","B","C"])In [24]:
Changes to str.cat
The method .str.cat() concatenates the members of a Series. Before, if NaN values were present in the Series, calling .str.cat() on it would return NaN, unlike the rest of the Series.str.* API. This behavior has been amended to ignore NaN values by default. (GH 11435).
A new, friendlier ValueError is added to protect against the mistake of supplying the sep as an arg, rather than as a kwarg. (GH 11334).
Datetimelike rounding
DatetimeIndex, Timestamp, TimedeltaIndex, Timedelta have gained the .round(), .floor() and .ceil() method for datetimelike rounding, flooring and ceiling. (GH 4314, GH 11963)
Naive datetimes
In [29]: dr
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 (GH 11713)
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,
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. (GH 10503)
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. (GH 11972)
DataFrame has gained a ._repr_latex_() method in order to allow for conversion to latex in a ipython/jupyter notebook using nbconvert. (GH 11778)
Note that this must be activated by setting the option pd.display.latex.repr=True (GH 12182)
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 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. (GH 4052)
Other enhancements
Handle truncated floats in SAS xport files (GH 11713)
Added option to hide index in Series.to_string (GH 11729)
read_excel now supports s3 urls of the format s3://bucketname/filename (GH 11447)
add support for AWS_S3_HOST env variable when reading from s3 (GH 12198)
A simple version of Panel.round() is now implemented (GH 11763)
Backwards incompatible API changes
the leading white spaces have been removed from the output of .to_string(index=False) method (GH 11833)
the out parameter has been removed from the Series.round() method. (GH 11763)
DataFrame.round() leaves non-numeric columns unchanged in its return, rather than raises. (GH 11885)
DataFrame.head(0) and DataFrame.tail(0) return empty frames, rather than self. (GH 11937)
Series.head(0) and Series.tail(0) return empty series, rather than self. (GH 11937)
to_msgpack and read_msgpack encoding now defaults to 'utf-8'. (GH 12170)
the order of keyword arguments to text file parsing functions (.read_csv(), .read_table(), .read_fwf()) changed to group related arguments. (GH 11555)
NaTType.isoformat now returns the string 'NaT to allow the result to
be passed to the constructor of Timestamp. (GH 12300)
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 (GH 11564).
NaT now supports arithmetic operations with integers and floats.
In [58]: pd.NaT*
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 (GH 12129, GH 10527)
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 (GH 12142). The following table describes the backward and forward compat of msgpacks.
Signature change for .rank
Series.rank and DataFrame.rank now have the same signature (GH 11759)
Previous signature
In [3]: pd.Series([0,1]).rank(method='average',na_option='keep', ascending=True, pct=False)Out[3]:
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. (GH 11406)
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]: dOut[74]: Timestamp('2014-02-01 00:00:00')In [75]: d+pd.
In prior versions, new columns assignments in an eval expression resulted
in an inplace change to the DataFrame. (GH 9297, GH 8664, GH 10486)
In [91]: df=pd.DataFrame({'a':np.linspace(0,10,5
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. (GH 11818)
In [107]: s=pd.Series(range(10),pd.date_range('2015-01-01'
Deprecations
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) (GH 11603)
In [1]: s=pd.Series(range(3))In [2]: pd.
Removal of deprecated float indexers
In GH 4892 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. (GH 12165, GH 12333)
In [104]: s=pd.Series([1,2,3],index=
Removal of prior version deprecations/changes
Removal of rolling_corr_pairwise in favor of .rolling().corr(pairwise=True) (GH 4950)
Removal of expanding_corr_pairwise in favor of .expanding().corr(pairwise=True) (GH 4950)
Removal of DataMatrix module. This was not imported into the pandas namespace in any event (GH 12111)
Improved performance in construction of Categoricals with Series of datetimes containing NaT (GH 12077)
Improved performance of ISO 8601 date parsing for dates without separators (GH 11899), leading zeros (GH 11871) and with white space preceding the time zone (GH 9714)
Bug fixes
Bug in GroupBy.size when data-frame is empty. (GH 11699)
Bug in Period.end_time when a multiple of time period is requested (GH 11738)
Regression in .clip with tz-aware datetimes (GH 11838)
Bug in date_range when the boundaries fell on the frequency (GH 11804, GH 12409)
Bug in consistency of passing nested dicts to .groupby(...).agg(...) (GH 9052)
Accept unicode in Timedelta constructor (GH 11995)
Bug in value label reading for StataReader when reading incrementally (GH 12014)
Bug in vectorized DateOffset when n parameter is 0 (GH 11370)
Compat for numpy 1.11 w.r.t. NaT comparison changes (GH 12049)
Bug in read_csv when reading from a StringIO in threads (GH 11790)
Bug in not treating NaT as a missing value in datetimelikes when factorizing & with Categoricals (GH 12077)
Bug in getitem when the values of a Series were tz-aware (GH 12089)
Bug in Series.str.get_dummies when one of the variables was ‘name’ (GH 12180)
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.
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(r'[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)Out[1]:0 11 22 NaNdtype: object
Extracting a regular expression with one group returns a Series if
expand=False.
In [16]: pd.Series(['a1','b2','c3']).str.extract(r'[ab](\d)',expand=False)Out[16]: 0 11 22 NaNLength: 3, dtype: object
It returns a DataFrame with one column if expand=True.
In [17]: pd.Series(['a1','b2','c3']).str.extract(r'[ab](\d)',expand=True)Out[17]: 00 11 22 NaN[3 rows x 1 columns]
Calling on an Index with a regex with exactly one capture group
returns an Index if expand=False.
It returns a DataFrame with one column if expand=True.
In [21]: s.index.str.extract("(?P<letter>[a-zA-Z])",expand=True)Out[21]: letter0 A1 B2 C[3 rows x 1 columns]
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)Out[22]: letter 10 A 111 B 222 C 33[3 rows x 2 columns]
In summary, extract(expand=True) always returns a DataFrame
with a row for every subject string, and a column for every capture
group.
s
Out[24]:
A a1a2
B b1
C c1
Length: 3, dtype: object
In [25]:
s
.
str
.
extract
(
r
"(?P<letter>[ab])(?P<digit>\d)"
,
expand
=
False
)
Out[25]:
letter digit
A a 1
B b 1
C NaN NaN
[3 rows x 2 columns]
The extractall method returns all matches.
In [26]: s.str.extractall(r"(?P<letter>[ab])(?P<digit>\d)")Out[26]: letter digit match A 0 a 1 1 a 2B 0 b 1[3 rows x 2 columns]
In [27]: pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ')Out[27]: 'a b c'In [28]: pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ',na_rep='?')Out[28]: 'a b ? c'
In [2]: pd.Series(['a','b',np.nan,'c']).str.cat(' ')ValueError: Did you mean to supply a ``sep`` keyword?
In [37]: t=pd.timedelta_range('1 days 2 hr 13 min 45 us',periods=3,freq='d')In [38]: tOut[38]: 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 scalarIn [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 through the .dt accessor of Series.
In [49]: df=pd.DataFrame({'a':[0,1,1], ....: 'b':pd.Series([100,200,300],dtype='uint32')}) ....: In [50]: df.dtypesOut[50]: a int64b uint32Length: 2, dtype: objectIn [51]: ix=df['a']==1In [52]: df.loc[ix,'b']=df.loc[ix,'b']In [53]: df.dtypesOut[53]: a int64b uint32Length: 2, dtype: object
When a DataFrame’s integer slice is partially updated with a new slice of floats that could potentially be down-casted 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), columns=list('abc'), index=[[4,4,8], [8,10,12]])In [5]: dfOut[5]: a b c4 8 1 2 3 10 4 5 68 12 7 8 9In [7]: df.ix[4,'c']=np.array([0.,1.])In [8]: dfOut[8]: a b c4 8 1 2 0 10 4 5 18 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]: dfOut[55]: a b c4 8 1 2 3 10 4 5 68 12 7 8 9[3 rows x 3 columns]In [56]: df.loc[4,'c']=np.array([0.,1.])In [57]: dfOut[57]: a b c4 8 1 2 0 10 4 5 18 12 7 8 9[3 rows x 3 columns]
DataFrame.quantile and Series.quantile now accept interpolation keyword (GH 10174).
Added DataFrame.style.format for more flexible formatting of cell values (GH 11692)
DataFrame.select_dtypes now allows the np.float16 type code (GH 11990)
pivot_table() now accepts most iterables for the values parameter (GH 12017)
Added Google BigQuery service account authentication support, which enables authentication on remote servers. (GH 11881, GH 12572). For further details see here
HDFStore is now iterable: forkinstore is equivalent to forkinstore.keys() (GH 12221).
Add missing methods/fields to .dt for Period (GH 8848)
The entire code base has been PEP-ified (GH 12096)
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.NaTOut[62]: nanIn [63]: pd.Timedelta('1s')/pd.NaTOut[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.NaTOut[64]: NaT# same asIn [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]')Out[66]: 0 NaTLength: 1, dtype: timedelta64[ns]
Timedelta division by floats now works.
In [67]: pd.Timedelta('1s')/2.0Out[67]: Timedelta('0 days 00:00:00.500000')
Subtraction by Timedelta in a Series by a Timestamp works (GH 11925)
NaT.isoformat() now returns 'NaT'. This change allows
pd.Timestamp to rehydrate any timestamp like object from its isoformat
(GH 12300).
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.
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')Out[6]: A B C D2010-01-01 09:00:00 0.485748 0.447351 0.357096 0.7936152010-01-01 09:00:02 0.820801 0.794317 0.364034 0.5310962010-01-01 09:00:04 0.433985 0.314582 0.424104 0.6257332010-01-01 09:00:06 0.624988 0.609738 0.633165 0.6124522010-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')Out[7]: A B C D2010-01-01 09:00:00 0.971495 0.894701 0.714192 1.5872312010-01-01 09:00:02 1.641602 1.588635 0.728068 1.0621912010-01-01 09:00:04 0.867969 0.629165 0.848208 1.2514652010-01-01 09:00:06 1.249976 1.219477 1.266330 1.2249042010-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]: rOut[83]: <pandas.core.resample.DatetimeIndexResampler object at 0x7f8c4690dc90>
Downsampling
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()Out[84]: A B C D2010-01-01 09:00:00 0.485748 0.447351 0.357096 0.7936152010-01-01 09:00:02 0.820801 0.794317 0.364034 0.5310962010-01-01 09:00:04 0.433985 0.314582 0.424104 0.6257332010-01-01 09:00:06 0.624988 0.609738 0.633165 0.6124522010-01-01 09:00:08 0.510470 0.534317 0.573201 0.806949[5 rows x 4 columns]
In [85]: r.sum()Out[85]: A B C D2010-01-01 09:00:00 0.971495 0.894701 0.714192 1.5872312010-01-01 09:00:02 1.641602 1.588635 0.728068 1.0621912010-01-01 09:00:04 0.867969 0.629165 0.848208 1.2514652010-01-01 09:00:06 1.249976 1.219477 1.266330 1.2249042010-01-01 09:00:08 1.020940 1.068634 1.146402 1.613897[5 rows x 4 columns]
Furthermore, resample now supports getitem operations to perform the resample on specific columns.
In [86]: r[['A','C']].mean()Out[86]: A C2010-01-01 09:00:00 0.485748 0.3570962010-01-01 09:00:02 0.820801 0.3640342010-01-01 09:00:04 0.433985 0.4241042010-01-01 09:00:06 0.624988 0.6331652010-01-01 09:00:08 0.510470 0.573201[5 rows x 2 columns]
and .aggregate type operations.
In [87]: r.agg({'A':'mean','B':'sum'})Out[87]: A B2010-01-01 09:00:00 0.485748 0.8947012010-01-01 09:00:02 0.820801 1.5886352010-01-01 09:00:04 0.433985 0.6291652010-01-01 09:00:06 0.624988 1.2194772010-01-01 09:00:08 0.510470 1.068634[5 rows x 2 columns]
These accessors can of course, be combined
In [88]: r[['A','B']].agg(['mean','sum'])Out[88]: A B mean sum mean sum2010-01-01 09:00:00 0.485748 0.971495 0.447351 0.8947012010-01-01 09:00:02 0.820801 1.641602 0.794317 1.5886352010-01-01 09:00:04 0.433985 0.867969 0.314582 0.6291652010-01-01 09:00:06 0.624988 1.249976 0.609738 1.2194772010-01-01 09:00:08 0.510470 1.020940 0.534317 1.068634[5 rows x 4 columns]
Upsampling
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 [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]: dfOut[13]: a b c0 0.0 0 0.01 2.5 1 3.52 5.0 2 7.03 7.5 3 10.54 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 [93]: dfOut[93]: a b c0 0.0 0 0.01 2.5 1 3.52 5.0 2 7.03 7.5 3 10.54 10.0 4 14.0[5 rows x 3 columns]In [94]: df.eval('d = c - b',inplace=False)Out[94]: a b c d0 0.0 0 0.0 0.01 2.5 1 3.5 2.52 5.0 2 7.0 5.03 7.5 3 10.5 7.54 10.0 4 14.0 10.0[5 rows x 4 columns]In [95]: dfOut[95]: a b c0 0.0 0 0.01 2.5 1 3.52 5.0 2 7.03 7.5 3 10.54 10.0 4 14.0[5 rows x 3 columns]In [96]: df.eval('d = c - b',inplace=True)In [97]: dfOut[97]: a b c d0 0.0 0 0.0 0.01 2.5 1 3.5 2.52 5.0 2 7.0 5.03 7.5 3 10.5 7.54 10.0 4 14.0 10.0[5 rows x 4 columns]
The inplace keyword parameter was also added the query method.
In [98]: df.query('a > 5')Out[98]: a b c d3 7.5 3 10.5 7.54 10.0 4 14.0 10.0[2 rows x 4 columns]In [99]: df.query('a > 5',inplace=True)In [100]: dfOut[100]: a b c d3 7.5 3 10.5 7.54 10.0 4 14.0 10.0[2 rows x 4 columns]
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 [101]: dfOut[101]: a b c d3 7.5 3 10.5 7.54 10.0 4 14.0 10.0[2 rows x 4 columns]In [102]: df.eval(""" .....: e = d + a .....: f = e - 22 .....: g = f / 2.0""",inplace=True) .....: In [103]: dfOut[103]: a b c d e f g3 7.5 3 10.5 7.5 15.0 -7.0 -3.54 10.0 4 14.0 10.0 20.0 -2.0 -1.0[2 rows x 7 columns]
,
freq
=
'H'
,
periods
=
10
))
In [108]:
s
.
between_time
(
"7:00am"
,
"9:00am"
)
Out[108]:
2015-01-01 07:00:00 7
2015-01-01 08:00:00 8
2015-01-01 09:00:00 9
Freq: H, Length: 3, 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() (GH 11597)
DataFrame.to_latex() now supports non-ascii encodings (eg utf-8) in Python 2 with the parameter encoding (GH 7061)
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 (GH 12081)
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. (GH 9746)
As part of the new API for window functions and resampling, aggregation functions have been clarified, raising more informative error messages on invalid aggregations. (GH 9052). 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 (GH 12301)
.to_latex and .to_html gain a decimal parameter like .to_csv; the default is '.' (GH 12031)
More helpful error message when constructing a DataFrame with empty data but with indices (GH 8020)
.describe() will now properly handle bool dtype as a categorical (GH 6625)
More helpful error message with an invalid .transform with user defined input (GH 10165)
Exponentially weighted functions now allow specifying alpha directly (GH 10789) and raise ValueError if parameters violate 0<alpha<=1 (GH 12492)
rolling_mean
(
s
,
window
=
2
,
min_periods
=
1
)
FutureWarning: pd.rolling_mean is deprecated for Series and
FutureWarning: pd.rolling_cov is deprecated for Series and
will be removed in a future version, replace with
Series.rolling(window=2).cov(other=<Series>)
Out[3]:
0 NaN
1 0.5
2 0.5
dtype: float64
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. (GH 11603).
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 (GH 11192)
pandas.stats.fama_macbeth routines are deprecated and will be removed in a future version (GH 6077)
pandas.stats.ols, pandas.stats.plm and pandas.stats.var routines are deprecated and will be removed in a future version (GH 6077)
show a FutureWarning rather than a DeprecationWarning on using long-time deprecated syntax in HDFStore.select, where the where clause is not a string-like (GH 12027)
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 (GH 11783).
[
4
,
5
,
6
])
In [105]:
s
Out[105]:
4 1
5 2
6 3
Length: 3, dtype: int64
In [106]:
s2
=
pd
.
Series
([
1
,
2
,
3
],
index
=
list
(
'abc'
))
In [107]:
s2
Out[107]:
a 1
b 2
c 3
Length: 3, dtype: int64
Previous behavior:
# this is label indexingIn [2]: s[5.0]FutureWarning: scalar indexers for index type Int64Index should be integers and not floating pointOut[2]: 2# this is positional indexingIn [3]: s.iloc[1.0]FutureWarning: scalar indexers for index type Int64Index should be integers and not floating pointOut[3]: 2# this is label indexingIn [4]: s.loc[5.0]FutureWarning: scalar indexers for index type Int64Index should be integers and not floating pointOut[4]: 2# .ix would coerce 1.0 to the positional 1, and indexIn [5]: s2.ix[1.0]=10FutureWarning: scalar indexers for index type Index should be integers and not floating pointIn [6]: s2Out[6]:a 1b 10c 3dtype: 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 [108]: s[5.0]Out[108]: 2In [109]: s.loc[5.0]Out[109]: 2
Removal of the read_frame and frame_query (both aliases for pd.read_sql)
and write_frame (alias of to_sql) functions in the pd.io.sql namespace,
deprecated since 0.14.0 (GH 6292).
Removal of the order keyword from .factorize() (GH 6930)