版本0.7.0(2012年2月9日)#

新功能#

  • 新的统一 merge function 用于高效地执行数据库/关系代数操作的全域。重构现有连接方法以使用新的基础设施,从而大幅提升性能 (GH220GH249GH267 )

  • New unified concatenation function for concatenating Series, DataFrame or Panel objects along an axis. Can form union or intersection of the other axes. Improves performance of Series.append and DataFrame.append (GH468, GH479, GH273)

  • 可以将多个DataFrame传递给 DataFrame.append 将(堆叠)和多个系列连接到 Series.append

  • Can 将字典列表(例如,JSON对象列表)传递给DataFrame构造函数 (GH526 )

  • 你现在可以 set multiple columns 在DataFrame Via中 __getitem__ ,对转型很有用 (GH342 )

  • Handle differently-indexed output values in DataFrame.apply (GH498)

In [1]: df = pd.DataFrame(np.random.randn(10, 4))
In [2]: df.apply(lambda x: x.describe())
Out[2]:
               0          1          2          3
count  10.000000  10.000000  10.000000  10.000000
mean    0.190912  -0.395125  -0.731920  -0.403130
std     0.730951   0.813266   1.112016   0.961912
min    -0.861849  -2.104569  -1.776904  -1.469388
25%    -0.411391  -0.698728  -1.501401  -1.076610
50%     0.380863  -0.228039  -1.191943  -1.004091
75%     0.658444   0.057974  -0.034326   0.461706
max     1.212112   0.577046   1.643563   1.071804

[8 rows x 4 columns]
  • Add reorder_levels 序列和DataFrame的方法 (GH534 )

  • Add 类词典 get 对DataFrame和Panel的函数 (GH521 )

  • Add DataFrame.iterrows 用于高效地循环访问DataFrame的行的方法

  • 添加 DataFrame.to_panel 使用改编自 LongPanel.to_long

  • Add reindex_axis 添加到DataFrame的方法

  • Add level option to binary arithmetic functions on DataFrame and Series

  • Add level 选项添加到 reindexalign 用于跨级别广播值的Series和DataFrame方法 (GH542GH552 ,其他)

  • 将基于属性的项目访问添加到 Panel 并添加IPython补全 (GH563 )

  • Add logy 选项以执行以下操作 Series.plot 用于Y轴上的对数缩放

  • Add index and header options to DataFrame.to_string

  • Can 将多个DataFrame传递给 DataFrame.join 在索引上联接 (GH115 )

  • Can pass multiple Panels to Panel.join (GH115)

  • Added justify 参数为 DataFrame.to_string 允许不同的列标题对齐方式

  • Add sort GroupBy选项,以允许禁用组密钥排序,以获得潜在的加速 (GH595 )

  • Can 将MaskedArray传递给Series构造函数 (GH563 )

  • 通过属性和IPython完成添加面板项访问 (GH554 )

  • 实施 DataFrame.lookup ,花式索引类似物,用于检索值,给定行和列标签序列 (GH338 )

  • 可以传递一个 list of functions 在DataFrame上使用GROUPBY进行聚合,生成具有分层列的聚合结果 (GH166 )

  • 可以呼叫 cummincummax 在Series和DataFrame上分别获得累计最小值和最大值 (GH647 )

  • value_range 添加为实用程序函数以获取数据帧的最小和最大值 (GH288 )

  • 已添加 encoding 参数为 read_csvread_tableto_csvfrom_csv 对于非ASCII文本 (GH717 )

  • Added abs 方法应用于Pandas对象

  • Added crosstab 一种便于计算频率表的函数

  • Added isin 为对象编制索引的方法

  • Added level 参数为 xs DataFrame方法。

API更改为整数索引#

0.7.0中潜在风险最大的API更改之一,但也是最重要的更改之一,是对如何 整数索引 是关于基于标签的索引来处理的。下面是一个例子:

In [3]: s = pd.Series(np.random.randn(10), index=range(0, 20, 2))
In [4]: s
Out[4]:
0    -1.294524
2     0.413738
4     0.276662
6    -0.472035
8    -0.013960
10   -0.362543
12   -0.006154
14   -0.923061
16    0.895717
18    0.805244
Length: 10, dtype: float64

In [5]: s[0]
Out[5]: -1.2945235902555294

In [6]: s[2]
Out[6]: 0.41373810535784006

In [7]: s[4]
Out[7]: 0.2766617129497566

这与之前的行为完全相同。然而,如果你要一把钥匙 not 包含在0.6.1及更早版本的系列中,系列将 后退 基于位置的查找。这现在引发了一个 KeyError

In [2]: s[1]
KeyError: 1

此更改对DataFrame也有相同的影响:

In [3]: df = pd.DataFrame(np.random.randn(8, 4), index=range(0, 16, 2))

In [4]: df
    0        1       2       3
0   0.88427  0.3363 -0.1787  0.03162
2   0.14451 -0.1415  0.2504  0.58374
4  -1.44779 -0.9186 -1.4996  0.27163
6  -0.26598 -2.4184 -0.2658  0.11503
8  -0.58776  0.3144 -0.8566  0.61941
10  0.10940 -0.7175 -1.0108  0.47990
12 -1.16919 -0.3087 -0.6049 -0.43544
14 -0.07337  0.3410  0.0424 -0.16037

In [5]: df.ix[3]
KeyError: 3

为了支持纯基于整数的索引,添加了以下方法:

方法

描述

Series.iget_value(i)

检索存储在位置的值 i

Series.iget(i)

的别名 iget_value

DataFrame.irow(i)

检索 i -第7行

DataFrame.icol(j)

检索 j -第4列

DataFrame.iget_value(i, j)

检索行中的值 i 和列 j

关于基于标签的切片的API调整#

基于标签的切片使用 ix 现在要求对索引进行排序(单调) 除非 起点和终点都包含在索引中:

In [1]: s = pd.Series(np.random.randn(6), index=list('gmkaec'))

In [2]: s
Out[2]:
g   -1.182230
m   -0.276183
k   -0.243550
a    1.628992
e    0.073308
c   -0.539890
dtype: float64

那么这是可以的:

In [3]: s.ix['k':'e']
Out[3]:
k   -0.243550
a    1.628992
e    0.073308
dtype: float64

但这不是:

In [12]: s.ix['b':'h']
KeyError 'b'

如果对索引进行了排序,则可以进行“范围选择”:

In [4]: s2 = s.sort_index()

In [5]: s2
Out[5]:
a    1.628992
c   -0.539890
e    0.073308
g   -1.182230
k   -0.243550
m   -0.276183
dtype: float64

In [6]: s2.ix['b':'h']
Out[6]:
c   -0.539890
e    0.073308
g   -1.182230
dtype: float64

对系列的更改 [] 操作员#

As as notational convenience, you can pass a sequence of labels or a label slice to a Series when getting and setting values via [] (i.e. the __getitem__ and __setitem__ methods). The behavior will be the same as passing similar input to ix except in the case of integer indexing:

In [8]: s = pd.Series(np.random.randn(6), index=list('acegkm'))

In [9]: s
Out[9]:
a   -1.206412
c    2.565646
e    1.431256
g    1.340309
k   -1.170299
m   -0.226169
Length: 6, dtype: float64

In [10]: s[['m', 'a', 'c', 'e']]
Out[10]:
m   -0.226169
a   -1.206412
c    2.565646
e    1.431256
Length: 4, dtype: float64

In [11]: s['b':'l']
Out[11]:
c    2.565646
e    1.431256
g    1.340309
k   -1.170299
Length: 4, dtype: float64

In [12]: s['c':'k']
Out[12]:
c    2.565646
e    1.431256
g    1.340309
k   -1.170299
Length: 4, dtype: float64

在整数索引的情况下,行为将与以前完全相同(跟踪 ndarray ):

In [13]: s = pd.Series(np.random.randn(6), index=range(0, 12, 2))

In [14]: s[[4, 0, 2]]
Out[14]:
4    0.132003
0    0.410835
2    0.813850
Length: 3, dtype: float64

In [15]: s[1:5]
Out[15]:
2    0.813850
4    0.132003
6   -0.827317
8   -0.076467
Length: 4, dtype: float64

如果希望使用序列进行索引,并使用标签语义对整数索引进行切片,请使用 ix

其他API更改#

  • 已弃用的 LongPanel 类已完全删除

  • If Series.sort is called on a column of a DataFrame, an exception will now be raised. Before it was possible to accidentally mutate a DataFrame's column by doing df[col].sort() instead of the side-effect free method df[col].order() (GH316)

  • 各种各样的更名和贬低会(无害地)引起 FutureWarning

  • drop added as an optional parameter to DataFrame.reset_index (GH699)

性能改进#

  • Cythonized GroupBy aggregations 不再预先排序数据,从而实现显著的加速 (GH93 )。GroupBy通过巧妙地处理Cython中的ndarray数据类型,显著提高了与Python函数的聚合速度 (GH496 )。

  • 当传递的列标签与数据不匹配时,DataFrame构造函数中更好的错误消息 (GH497 )

  • 显著提高多组的性能通过在传递Python函数时进行聚合,在Cython中重用ndarray对象 (GH496 )

  • 可以将按元组和浮点数索引的对象存储在HDFStore中 (GH492 )

  • 在序列中不打印默认长度。to_string,添加 length 选项 (GH489 )

  • 改进Cython代码,以便在不对数据进行排序的情况下进行聚合 (GH93 )

  • 通过将元组存储在多索引中来提高多索引重建索引的速度,测试向后取消酸洗的兼容性

  • 通过使用专门的Cython Take函数提高列重新索引性能

  • 进一步调整性能 Series.__getitem__ 对于标准用例

  • 避免在某些情况下(例如,在获取切片时)创建索引字典,避免从先前版本回归

  • 如果未安装NumPy,则在setup.py中显示更友好的错误消息

  • 使用NA处理操作的公共集合(求和、求平均值等)在Panel类中也是 (GH536 )

  • 调用时的默认名称分配 reset_index 关于具有常规(非分层)索引的DataFrame (GH476 )

  • 尽可能在系列/数据帧统计操作中使用Cythonated Grouper level 传递的参数 (GH545 )

  • 将跳过列表数据结构移植到C语言以提高速度 rolling_median 在大多数典型用例中提高约5-10倍 (GH374 )

贡献者#

共有18人为此次发布贡献了补丁。名字中带有“+”的人第一次贡献了一个补丁。

  • Adam Klein

  • Bayle Shanks +

  • Chris Billington +

  • Dieter Vandenbussche

  • Fabrizio Pollastri +

  • Graham Taylor +

  • Gregg Lind +

  • Josh Klein +

  • Luca Beltrame

  • Olivier Grisel +

  • Skipper Seabold

  • Thomas Kluyver

  • Thomas Wiecki +

  • Wes McKinney

  • Wouter Overmeire

  • Yaroslav Halchenko

  • fabriziop +

  • theandygross +