版本0.13.1(2014年2月3日)#
这是0.13.0的次要版本,包括少量的API更改、几个新功能、增强功能和性能改进,以及大量的错误修复。我们建议所有用户升级到此版本。
亮点包括:
已添加
infer_datetime_format
关键字至read_csv/to_datetime
以加速同种格式的日期时间。将智能地限制日期时间/时间增量格式的显示精度。
增强型面板
apply()
方法。新版本中的建议教程 Tutorials 部分。
我们的Pandas生态系统正在增长,我们现在在一个新的 Pandas Ecosystem 部分。
在改进文档方面进行了大量工作,并推出了一个新的 Contributing 部分已添加。
尽管它可能只对开发人员感兴趣,但我们<3新的配置项状态页面: ScatterCI 。
警告
0.13.1修复了一个错误,该错误是由NumPy<1.8和在字符串型数组上执行链式赋值的组合引起的。请审阅 the docs ,链式索引可能会产生意外的结果,通常应避免。
这在以前会出现段错:
In [1]: df = pd.DataFrame({"A": np.array(["foo", "bar", "bah", "foo", "bar"])})
In [2]: df["A"].iloc[0] = np.nan
In [3]: df
Out[3]:
A
0 NaN
1 bar
2 bah
3 foo
4 bar
执行此类任务的建议方式为:
In [4]: df = pd.DataFrame({"A": np.array(["foo", "bar", "bah", "foo", "bar"])})
In [5]: df.loc[0, "A"] = np.nan
In [6]: df
Out[6]:
A
0 NaN
1 bar
2 bah
3 foo
4 bar
输出格式增强功能#
Df.info()视图现在按列显示dtype信息 (GH5682 )
Df.info()现在支持该选项
max_info_rows
,以禁用大帧的空值计数 (GH5974 )In [7]: max_info_rows = pd.get_option("max_info_rows") In [8]: df = pd.DataFrame( ...: { ...: "A": np.random.randn(10), ...: "B": np.random.randn(10), ...: "C": pd.date_range("20130101", periods=10), ...: } ...: ) ...: In [9]: df.iloc[3:6, [0, 2]] = np.nan
# set to not display the null counts In [10]: pd.set_option("max_info_rows", 0) In [11]: df.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 10 entries, 0 to 9 Data columns (total 3 columns): # Column Dtype --- ------ ----- 0 A float64 1 B float64 2 C datetime64[ns] dtypes: datetime64[ns](1), float64(2) memory usage: 368.0 bytes
# this is the default (same as in 0.13.0) In [12]: pd.set_option("max_info_rows", max_info_rows) In [13]: df.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 10 entries, 0 to 9 Data columns (total 3 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 A 7 non-null float64 1 B 10 non-null float64 2 C 7 non-null datetime64[ns] dtypes: datetime64[ns](1), float64(2) memory usage: 368.0 bytes
添加
show_dimensions
用于控制是否打印维度的新DataFrame Repr的显示选项。In [14]: df = pd.DataFrame([[1, 2], [3, 4]]) In [15]: pd.set_option("show_dimensions", False) In [16]: df Out[16]: 0 1 0 1 2 1 3 4 In [17]: pd.set_option("show_dimensions", True) In [18]: df Out[18]: 0 1 0 1 2 1 3 4 [2 rows x 2 columns]
这个
ArrayFormatter
为datetime
和timedelta64
现在,根据数组中的值智能地限制精度 (GH3401 )以前的输出可能如下所示:
age today diff 0 2001-01-01 00:00:00 2013-04-19 00:00:00 4491 days, 00:00:00 1 2004-06-01 00:00:00 2013-04-19 00:00:00 3244 days, 00:00:00
现在,输出如下所示:
In [19]: df = pd.DataFrame( ....: [pd.Timestamp("20010101"), pd.Timestamp("20040601")], columns=["age"] ....: ) ....: In [20]: df["today"] = pd.Timestamp("20130419") In [21]: df["diff"] = df["today"] - df["age"] In [22]: df Out[22]: 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]
API更改#
已添加
Series.str.get_dummies
矢量化字符串方法 (GH6021 ),要提取分隔字符串列的伪/指示符变量:In [23]: s = pd.Series(["a", "a|b", np.nan, "a|c"]) In [24]: s.str.get_dummies(sep="|") Out[24]: a b c 0 1 0 0 1 1 1 0 2 0 0 0 3 1 0 1 [4 rows x 3 columns]
添加了
NDFrame.equals()
用于比较两个NDFrame是否相等的方法具有相等的轴、数据类型和值。添加了array_equivalent
函数来比较两个ndarray是否相等。位于相同位置的NAN被同等对待。 (GH5283 )另请参阅 the docs 这是一个鼓舞人心的例子。df = pd.DataFrame({"col": ["foo", 0, np.nan]}) df2 = pd.DataFrame({"col": [np.nan, 0, "foo"]}, index=[2, 1, 0]) df.equals(df2) df.equals(df2.sort_index())
DataFrame.apply
将使用reduce
参数来确定是否使用Series
或者是DataFrame
时应返回DataFrame
是空的 (GH6007 )。之前,调用
DataFrame.apply
空荡荡的DataFrame
将返回一个DataFrame
如果没有列,或者正在应用的函数将使用空Series
要猜测一个Series
或DataFrame
应退回:In [32]: def applied_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 NaN b NaN Length: 2, dtype: float64
现在,当
apply
在空值上被调用DataFrame
:如果reduce
论据是True
一个Series
威尔回来了,如果是的话False
一个DataFrame
将被返回,如果它是None
(默认)将使用空序列调用所应用的函数,以尝试并猜测返回类型。In [35]: empty.apply(applied_func, reduce=True) Out[35]: a NaN b NaN Length: 2, dtype: float64 In [36]: empty.apply(applied_func, reduce=False) Out[36]: Empty DataFrame Columns: [a, b] Index: [] [0 rows x 2 columns]
先前版本的弃用/更改#
0.13或更早版本中没有宣布的更改将于0.13.1生效
不推荐使用#
0.13.1中没有对先前行为的贬低
增强#
pd.read_csv
和pd.to_datetime
学到了一个新的infer_datetime_format
关键字,这在许多情况下极大地提高了解析性能。感谢@lexual的建议和@danBirken的快速实施。 (GH5490 , GH6021 )如果
parse_dates
如果启用并设置了此标志,则Pandas将尝试推断列中日期时间字符串的格式,如果可以推断,则切换到更快的解析方法。在某些情况下,这可以将解析速度提高约5-10倍。# Try to infer the format for the index column df = pd.read_csv( "foo.csv", index_col=0, parse_dates=True, infer_datetime_format=True )
date_format
和datetime_format
现在可以在写入时指定关键字excel
文件 (GH4133 )MultiIndex.from_product
用于从一组迭代的笛卡尔乘积创建多重索引的便利函数 (GH6055 ):In [25]: shades = ["light", "dark"] In [26]: colors = ["red", "green", "blue"] In [27]: pd.MultiIndex.from_product([shades, colors], names=["shade", "color"]) Out[27]: MultiIndex([('light', 'red'), ('light', 'green'), ('light', 'blue'), ( 'dark', 'red'), ( 'dark', 'green'), ( 'dark', 'blue')], names=['shade', 'color'])
嵌板
apply()
将对非UFFICS起作用。看见 the docs 。In [28]: import pandas._testing as tm In [29]: panel = tm.makePanel(5) In [30]: panel Out[30]: <class 'pandas.core.panel.Panel'> Dimensions: 3 (items) x 5 (major_axis) x 4 (minor_axis) Items axis: ItemA to ItemC Major_axis axis: 2000-01-03 00:00:00 to 2000-01-07 00:00:00 Minor_axis axis: A to D In [31]: 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]
指定一个
apply
对序列进行操作(以返回单个元素)In [32]: panel.apply(lambda x: x.dtype, axis='items') Out[32]: A B C D 2000-01-03 float64 float64 float64 float64 2000-01-04 float64 float64 float64 float64 2000-01-05 float64 float64 float64 float64 2000-01-06 float64 float64 float64 float64 2000-01-07 float64 float64 float64 float64 [5 rows x 4 columns]
类似的归约类型操作
In [33]: panel.apply(lambda x: x.sum(), axis='major_axis') Out[33]: ItemA ItemB ItemC A -1.108775 -1.090118 -2.984435 B -3.705764 0.409204 1.866240 C 2.110856 2.960500 -0.974967 D -4.532785 0.303202 -3.685193 [4 rows x 3 columns]
这相当于
In [34]: panel.sum('major_axis') Out[34]: ItemA ItemB ItemC A -1.108775 -1.090118 -2.984435 B -3.705764 0.409204 1.866240 C 2.110856 2.960500 -0.974967 D -4.532785 0.303202 -3.685193 [4 rows x 3 columns]
一个转换操作,它返回一个Panel,但正在计算MAJOR_AXIS上的z分数
In [35]: result = panel.apply(lambda x: (x - x.mean()) / x.std(), ....: axis='major_axis') ....: In [36]: result Out[36]: <class 'pandas.core.panel.Panel'> Dimensions: 3 (items) x 5 (major_axis) x 4 (minor_axis) Items axis: ItemA to ItemC Major_axis axis: 2000-01-03 00:00:00 to 2000-01-07 00:00:00 Minor_axis axis: A to D In [37]: result['ItemA'] # noqa E999 Out[37]: A B C D 2000-01-03 -0.535778 1.500802 -1.506416 -0.681456 2000-01-04 0.397628 -1.108752 0.360481 1.529895 2000-01-05 -1.489811 -0.339412 0.557374 0.280845 2000-01-06 0.885279 0.421830 -0.453013 -1.053785 2000-01-07 0.742682 -0.474468 1.041575 -0.075499 [5 rows x 4 columns]
嵌板
apply()
在横断面板上运行。 (GH1148 )In [38]: def f(x): ....: return ((x.T - x.mean(1)) / x.std(1)).T ....: In [39]: result = panel.apply(f, axis=['items', 'major_axis']) In [40]: result Out[40]: <class 'pandas.core.panel.Panel'> Dimensions: 4 (items) x 5 (major_axis) x 3 (minor_axis) Items axis: A to D Major_axis axis: 2000-01-03 00:00:00 to 2000-01-07 00:00:00 Minor_axis axis: ItemA to ItemC In [41]: result.loc[:, :, 'ItemA'] Out[41]: A B C D 2000-01-03 0.012922 -0.030874 -0.629546 -0.757034 2000-01-04 0.392053 -1.071665 0.163228 0.548188 2000-01-05 -1.093650 -0.640898 0.385734 -1.154310 2000-01-06 1.005446 -1.154593 -0.595615 -0.809185 2000-01-07 0.783051 -0.198053 0.919339 -1.052721 [5 rows x 4 columns]
这相当于以下内容
In [42]: result = pd.Panel({ax: f(panel.loc[:, :, ax]) for ax in panel.minor_axis}) In [43]: result Out[43]: <class 'pandas.core.panel.Panel'> Dimensions: 4 (items) x 5 (major_axis) x 3 (minor_axis) Items axis: A to D Major_axis axis: 2000-01-03 00:00:00 to 2000-01-07 00:00:00 Minor_axis axis: ItemA to ItemC In [44]: result.loc[:, :, 'ItemA'] Out[44]: A B C D 2000-01-03 0.012922 -0.030874 -0.629546 -0.757034 2000-01-04 0.392053 -1.071665 0.163228 0.548188 2000-01-05 -1.093650 -0.640898 0.385734 -1.154310 2000-01-06 1.005446 -1.154593 -0.595615 -0.809185 2000-01-07 0.783051 -0.198053 0.919339 -1.052721 [5 rows x 4 columns]
性能#
0.13.1的性能改进
实验性的#
在0.13.1中没有实验变化
错误修复#
窃听
io.wb.get_countries
不包括所有国家 (GH6008 )用时间戳字典替换系列中的错误 (GH5797 )
READ_CSV/READ_TABLE现在支持
prefix
科瓦格 (GH5732 )。通过以下方式选择时出现错误:缺少值
.ix
从重复的索引DataFrame失败 (GH5835 )修复了空DataFrame上的布尔比较问题 (GH5808 )
IsNULL处理中存在错误
NaT
在对象数组中 (GH5443 )窃听
to_datetime
当传递给np.nan
或类似日期的整数和格式字符串 (GH5863 )使用类似日期时间的Groupby数据类型转换时出现错误 (GH5869 )
处理空序列作为序列索引器的回归 (GH5877 )
内部缓存中的错误,与 (GH5727 )
在PY3下的Windows上从非文件路径读取JSON/msgpack时测试错误 (GH5874 )
Bug when assigning to .ix[tuple(...)] (GH5896)
完全重新索引面板时出现错误 (GH5905 )
对象数据类型的idxmin/max中存在错误 (GH5914 )
窃听
BusinessDay
当n>5且n%5==0时,将n天添加到非偏移量上的日期 (GH5890 )通过IX向具有系列的链接系列赋值时出现错误 (GH5928 )
创建空DataFrame、复制,然后分配时出错 (GH5932 )
框架为空的DataFrame.ail中存在错误 (GH5846 )
Bug in propagating metadata on
resample
(GH5862)固定字符串-表示
NaT
做一个“纳特” (GH5708 )修复了时间戳的字符串表示形式,以显示纳秒(如果存在 (GH5912 )
pd.match
不返回通过的哨兵Panel.to_frame()
no longer fails whenmajor_axis
is aMultiIndex
(GH5402).窃听
pd.read_msgpack
用来推断DateTimeIndex
频率不正确 (GH5947 )固定的
to_datetime
对于同时具有TZ感知日期时间和NaT
%s (GH5961 )在传递包含错误数据的序列时出现滚动倾斜/峰度错误 (GH5749 )
Scipy中的Bug
interpolate
具有DateTime索引的方法 (GH5975 )如果传递了带有NAT的混合DateTime/np.DateTime64,则NAT比较中出现错误 (GH5968 )
修复了的错误
pd.concat
如果所有输入均为空,则丢失数据类型信息 (GH5742 )IPython中的最新更改会导致在QTConsole中使用以前版本的Pandas时发出警告,现已修复。如果您使用的是旧版本,并且需要取消显示警告,请参见 (GH5922 )。
合并中的错误
timedelta
数据类型 (GH5695 )绘制中的错误。散布_矩阵函数。对角线和非对角线地块之间的错误对齐,请参见 (GH5497 )。
通过IX实现的多指标级数回归 (GH6018 )
具有多索引的Series.xs中的错误 (GH6018 )
具有类日期和整数的混合类型的Series构造中存在错误(这应该会导致对象类型,而不是自动转换) (GH6028 )
在使用带有非标量(例如列表)的单个元素编制索引时设置错误, (GH6043 )
回归到
.get(None)
从0.12开始编制索引 (GH5652 )微妙
iloc
索引错误,出现在 (GH6059 )在DatetimeIndex中插入字符串时出现错误 (GH5818 )
修复了to_html/html epr中的Unicode错误 (GH6098 )
修复了GET_OPTIONS_DATA中缺少的参数验证 (GH6105 )
对位置为切片的帧中的重复列进行赋值时出错(例如,相邻) (GH6120 )
在构造具有DUPS索引/列的DataFrame期间,Proportating_ref_Locs中出现错误 (GH6121 )
窃听
DataFrame.apply
当使用混合的类似日期的缩减时 (GH6125 )窃听
DataFrame.append
在追加具有不同列的行时 (GH6129 )使用rec数组和非ns日期时间数据类型的DataFrame构造中存在错误 (GH6140 )
窃听
.loc
使用RHS上的数据帧、多项设置和类似日期时间的数据项索引 (GH6152 )修复了中的错误
query
/eval
在按词典顺序进行字符串比较期间 (GH6155 )。修复了中的错误
query
其中,单个元素的索引Series
被扔掉了 (GH6148 )。窃听
HDFStore
将具有多索引列的数据帧追加到现有表 (GH6167 )设置空DataFrame时与数据类型的一致性 (GH6171 )
在多索引上选择时出现错误
HDFStore
即使在未指定的列规格的情况下 (GH6169 )窃听
nanops.var
使用ddof=1
而%1元素有时会返回inf
而不是nan
在某些平台上 (GH6136 )系列和DataFrame条形图中的错误忽略
use_index
关键字 (GH6209 )修正了python3下str/int混合的Groupby中的错误;
argsort
失败了 (GH6212 )
贡献者#
共有52人为此次发布贡献了补丁。名字中带有“+”的人第一次贡献了一个补丁。
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