This is a minor release from 0.13.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.
Highlights include:
Added infer_datetime_format keyword to read_csv/to_datetime to allow speedups for homogeneously formatted datetimes.
Will intelligently limit display precision for datetime/timedelta formats.
Add -NaN and -nan to the default set of NA values (GH 5952).
See NA Values.
Added Series.str.get_dummies vectorized string method (GH 6021), to extract
dummy/indicator variables for separated string columns:
In [20]: s=pd.Series(["a","a|b",np.nan,"a|c"])In [21]: s.str.get_dummies(sep="|")Out[21]: a b c0 1 0 01 1 1 02 0 0 03 1 0 1[4 rows x 3 columns]
Added the NDFrame.equals() method to compare if two NDFrames are
equal have equal axes, dtypes, and values. Added the
array_equivalent function to compare if two ndarrays are
equal. NaNs in identical locations are treated as
equal. (GH 5283) See also the docs for a motivating example.
df=pd.DataFrame({"col":["foo",0,np.nan]})df2=pd.
DataFrame.apply will use the reduce argument to determine whether a
Series or a DataFrame should be returned when the DataFrame is
empty (GH 6007).
Previously, calling DataFrame.apply an empty DataFrame would return
either a DataFrame if there were no columns, or the function being
applied would be called with an empty Series to guess whether a
Series or should be returned:
Prior version deprecations/changes
There are no announced changes in 0.13 or prior that are taking effect as of 0.13.1
Deprecations
There are no deprecations of prior behavior in 0.13.1
Enhancements
pd.read_csv and pd.to_datetime learned a new infer_datetime_format keyword which greatly
improves parsing perf in many cases. Thanks to @lexual for suggesting and @danbirken
for rapidly implementing. (GH 5490, GH 6021)
If parse_dates is enabled and this flag is set, pandas will attempt to
infer the format of the datetime strings in the columns, and if it can
be inferred, switch to a faster method of parsing them. In some cases
this can increase the parsing speed by ~5-10x.
# Try to infer the format for the index columndf=pd.read_csv("foo.csv",index_col=0,parse_dates=True,infer_datetime_format=True)
date_format and datetime_format keywords can now be specified when writing to excel
files (GH 4133)
MultiIndex.from_product convenience function for creating a MultiIndex from
the cartesian product of a set of iterables (GH 6055):
In [22]: shades=["light","dark"]In [23]: colors=["red","green","blue"]In [24]: pd.MultiIndex.from_product([shades,
Panel apply() will work on non-ufuncs. See the docs.
In [28]: importpandas._testingastmIn [29]: panel=tm.makePanel(5)In [30]: panelOut[30]:<class 'pandas.core.panel.Panel'>Dimensions: 3 (items) x 5 (major_axis) x 4 (minor_axis)Items axis: ItemA to ItemCMajor_axis axis: 2000-01-03 00:00:00 to 2000-01-07 00:00:00Minor_axis axis: A to DIn [31]:
Panel apply() operating on cross-sectional slabs. (GH 1148)
In [38]: deff(x): ....: return((x.T-x.mean(1))/x.std(1)).T
Performance
Performance improvements for 0.13.1
Series datetime/timedelta binary operations (GH 5801)
DataFrame count/dropna for axis=1
Series.str.contains now has a regex=False keyword which can be faster for plain (non-regex) string patterns. (GH 5879)
Fixed string-representation of NaT to be “NaT” (GH 5708)
Fixed string-representation for Timestamp to show nanoseconds if present (GH 5912)
pd.match not returning passed sentinel
Panel.to_frame() no longer fails when major_axis is a
MultiIndex (GH 5402).
Bug in pd.read_msgpack with inferring a DateTimeIndex frequency
incorrectly (GH 5947)
Fixed to_datetime for array with both Tz-aware datetimes and NaT’s (GH 5961)
Bug in rolling skew/kurtosis when passed a Series with bad data (GH 5749)
Bug in scipy interpolate methods with a datetime index (GH 5975)
Bug in NaT comparison if a mixed datetime/np.datetime64 with NaT were passed (GH 5968)
Fixed bug with pd.concat losing dtype information if all inputs are empty (GH 5742)
Recent changes in IPython cause warnings to be emitted when using previous versions
of pandas in QTConsole, now fixed. If you’re using an older version and
need to suppress the warnings, see (GH 5922).
Fixed missing arg validation in get_options_data (GH 6105)
Bug in assignment with duplicate columns in a frame where the locations
are a slice (e.g. next to each other) (GH 6120)
Bug in propagating _ref_locs during construction of a DataFrame with dups
index/columns (GH 6121)
Bug in DataFrame.apply when using mixed datelike reductions (GH 6125)
Bug in DataFrame.append when appending a row with different columns (GH 6129)
Bug in DataFrame construction with recarray and non-ns datetime dtype (GH 6140)
Bug in .loc setitem indexing with a dataframe on rhs, multiple item setting, and
a datetimelike (GH 6152)
Fixed a bug in query/eval during lexicographic string comparisons (GH 6155).
Fixed a bug in query where the index of a single-element Series was
being thrown away (GH 6148).
Bug in HDFStore on appending a dataframe with MultiIndexed columns to
an existing table (GH 6167)
Consistency with dtypes in setting an empty DataFrame (GH 6171)
Bug in selecting on a MultiIndex HDFStore even in the presence of under
specified column spec (GH 6169)
Bug in nanops.var with ddof=1 and 1 elements would sometimes return inf
rather than nan on some platforms (GH 6136)
Bug in Series and DataFrame bar plots ignoring the use_index keyword (GH 6209)
Bug in groupby with mixed str/int under python3 fixed; argsort was failing (GH 6212)
Contributors
A total of 52 people contributed patches to this release. People with a
“+” by their names contributed a patch for the first time.
Alex Rothberg
Alok Singhal +
Andrew Burrows +
Andy Hayden
Bjorn Arneson +
Brad Buran
Caleb Epstein
Chapman Siu
Chase Albert +
Clark Fitzgerald +
DSM
Dan Birken
Daniel Waeber +
David Wolever +
Doran Deluz +
Douglas McNeil +
Douglas Rudd +
Dražen Lučanin
Elliot S +
Felix Lawrence +
George Kuan +
Guillaume Gay +
Jacob Schaer
Jan Wagner +
Jeff Tratner
John McNamara
Joris Van den Bossche
Julia Evans +
Kieran O’Mahony
Michael Schatzow +
Naveen Michaud-Agrawal +
Patrick O’Keeffe +
Phillip Cloud
Roman Pekar
Skipper Seabold
Spencer Lyon
Tom Augspurger +
TomAugspurger
acorbe +
akittredge +
bmu +
bwignall +
chapman siu
danielballan
david +
davidshinn
immerrr +
jreback
lexual
mwaskom +
unutbu
y-p
Out[3]:
A
0 NaN
1 bar
2 bah
3 foo
4 bar
1 3 4
In [14]:
pd
.
set_option
(
"show_dimensions"
,
True
)
In [15]:
df
Out[15]:
0 1
0 1 2
1 3 4
[2 rows x 2 columns]
pd
.
Timestamp
(
"20010101"
),
pd
.
Timestamp
(
"20040601"
)],
columns
=
[
"age"
]
....:
)
....:
In [17]:
df
[
"today"
]
=
pd
.
Timestamp
(
"20130419"
)
In [18]:
df
[
"diff"
]
=
df
[
"today"
]
-
df
[
"age"
]
In [19]:
df
Out[19]:
age today diff
0 2001-01-01 2013-04-19 4491 days
1 2004-06-01 2013-04-19 3244 days
[2 rows x 3 columns]
DataFrame
({
"col"
:
[
np
.
nan
,
0
,
"foo"
]},
index
=
[
2
,
1
,
0
])
df
.
equals
(
df2
)
df
.
equals
(
df2
.
sort_index
())
DataFrame
In [32]: defapplied_func(col): ....: print("Apply function being called with: ", col) ....: return col.sum() ....:In [33]: empty=DataFrame(columns=['a','b'])In [34]: empty.apply(applied_func)Apply function being called with: Series([], Length: 0, dtype: float64)Out[34]:a NaNb NaNLength: 2, dtype: float64
Now, when apply is called on an empty DataFrame: if the reduce
argument is True a Series will returned, if it is False a
DataFrame will be returned, and if it is None (the default) the
function being applied will be called with an empty series to try and guess
the return type.
In [35]: empty.apply(applied_func,reduce=True)Out[35]:a NaNb NaNLength: 2, dtype: float64In [36]: empty.apply(applied_func,reduce=False)Out[36]:Empty DataFrameColumns: [a, b]Index: [][0 rows x 2 columns]
colors
],
names
=
[
"shade"
,
"color"
])
Out[24]:
MultiIndex([('light', 'red'),
('light', 'green'),
('light', 'blue'),
( 'dark', 'red'),
( 'dark', 'green'),
( 'dark', 'blue')],
names=['shade', 'color'])
panel
[
'ItemA'
]
Out[31]:
A B C D
2000-01-03 -0.673690 0.577046 -1.344312 -1.469388
2000-01-04 0.113648 -1.715002 0.844885 0.357021
2000-01-05 -1.478427 -1.039268 1.075770 -0.674600
2000-01-06 0.524988 -0.370647 -0.109050 -1.776904
2000-01-07 0.404705 -1.157892 1.643563 -0.968914
[5 rows x 4 columns]
Specifying an apply that operates on a Series (to return a single element)
In [32]: panel.apply(lambdax:x.dtype,axis='items')Out[32]: A B C D2000-01-03 float64 float64 float64 float642000-01-04 float64 float64 float64 float642000-01-05 float64 float64 float64 float642000-01-06 float64 float64 float64 float642000-01-07 float64 float64 float64 float64[5 rows x 4 columns]