This is a bug fix release from 0.9.0 and includes several new features and
enhancements along with a large number of bug fixes. The new features include
by-column sort order for DataFrame and Series, improved NA handling for the rank
method, masking functions for DataFrame, and intraday time-series filtering for
DataFrame.
New features
Series.sort, DataFrame.sort, and DataFrame.sort_index can now be
specified in a per-column manner to support multiple sort orders (GH 928)
In [2]:
df
=
pd
.
DataFrame
(
np
.
random
.
randint
(
0
,
2
,
(
6
,
3
)),
...:
columns
=
[
'A'
,
'B'
,
'C'
])
In [3]:
df
.
sort
([
'A'
,
'B'
],
ascending
=
[
1
,
0
])
Out[3]:
A B C
3 0 1 1
4 0 1 1
2 0 0 1
0 1 0 0
1 1 0 0
5 1 0 0
DataFrame.rank now supports additional argument values for the
na_option parameter so missing values can be assigned either the largest
or the smallest rank (GH 1508, GH 2159)
In [1]: df=pd.DataFrame(np.random.randn(6,3),columns=['A','B','C'])In [2]: df.loc[2:4]=np.nanIn [3]: df.rank()Out[3]: A B C0 3.0 2.0 1.01 1.0 3.0 2.02 NaN NaN NaN3 NaN NaN NaN4 NaN NaN NaN5 2.0 1.0 3.0[6 rows x 3 columns]In [4]: df.rank(na_option='top')Out[4]: A B C0 6.0 5.0 4.01 4.0 6.0 5.02 2.0 2.0 2.03 2.0 2.0 2.04 2.0 2.0 2.05 5.0 4.0 6.0[6 rows x 3 columns]In [5]: df.rank(na_option='bottom')Out[5]: A B C0 3.0 2.0 1.01 1.0 3.0 2.02 5.0 5.0 5.03 5.0 5.0 5.04 5.0 5.0 5.05 2.0 1.0 3.0[6 rows x 3 columns]
DataFrame has new where and mask methods to select values according to a
given boolean mask (GH 2109, GH 2151)
DataFrame currently supports slicing via a boolean vector the same length as the DataFrame (inside the []).
The returned DataFrame has the same number of columns as the original, but is sliced on its index.
In [6]: df=pd.DataFrame(np.random.randn(5,3),columns=['A','B','C'])In [7]: dfOut[7]: A B C0 0.276232 -1.087401 -0.6736901 0.113648 -1.478427 0.5249882 0.404705 0.577046 -1.7150023 -1.039268 -0.370647 -1.1578924 -1.344312 0.844885 1.075770[5 rows x 3 columns]In [8]: df[df['A']>0]Out[8]: A B C0 0.276232 -1.087401 -0.6736901 0.113648 -1.478427 0.5249882 0.404705 0.577046 -1.715002[3 rows x 3 columns]
If a DataFrame is sliced with a DataFrame based boolean condition (with the same size as the original DataFrame),
then a DataFrame the same size (index and columns) as the original is returned, with
elements that do not meet the boolean condition as NaN. This is accomplished via
the new method DataFrame.where. In addition, where takes an optional other argument for replacement.
In [9]: df[df>0]Out[9]: A B C0 0.276232 NaN NaN1 0.113648 NaN 0.5249882 0.404705 0.577046 NaN3 NaN NaN NaN4 NaN 0.844885 1.075770[5 rows x 3 columns]In [10]: df.where(df>0)Out[10]: A B C0 0.276232 NaN NaN1 0.113648 NaN 0.5249882 0.404705 0.577046 NaN
Furthermore, where now aligns the input boolean condition (ndarray or DataFrame), such that partial selection
with setting is possible. This is analogous to partial setting via .ix (but on the contents rather than the axis labels)
In [12]: df2=df.copy()In [13]: df2[df2[1:4]>0]=3In [14]: df2Out[14]: A B C0 0.276232 -1.087401 -0.6736901 3.000000 -1.478427 3.0000002 3.000000 3.000000 -1.7150023 -1.039268 -0.370647 -1.1578924 -1.344312 0.844885 1.075770
DataFrame.mask is the inverse boolean operation of where.
In [15]: df.mask(df<=0)Out[15]: A B C0 0.276232 NaN NaN1 0.113648 NaN 0.5249882 0.404705 0.577046 NaN3 NaN NaN NaN4 NaN 0.844885 1.075770[5 rows x 3 columns]
Enable referencing of Excel columns by their column names (GH 1936)
In [1]: xl=pd.ExcelFile('data/test.xls')In [2]: xl.parse('Sheet1',index_col=0,parse_dates=True, parse_cols='A:D')
Added option to disable pandas-style tick locators and formatters
using series.plot(x_compat=True) or pandas.plot_params['x_compat']=True (GH 2205)
Existing TimeSeries methods at_time and between_time were added to
DataFrame (GH 2149)