版本 0.13.0 (2014 年 1 月 3 日)#
这是 0.12.0 的一个主要版本,包含一些 API 变更、几个新特性和增强功能,以及大量的 bug 修复。
主要亮点包括
支持新的索引类型
Float64Index
,以及其他索引增强功能HDFStore
支持基于字符串的新查询语法支持新的插值方法
更新了
timedelta
操作新的字符串操作方法
extract
Offset 支持纳秒精度
DataFrames 的
isin
方法
添加了几个实验性特性,包括
用于表达式评估的新
eval/query
方法支持
msgpack
序列化用于访问 Google
BigQuery
的 I/O 接口
有几个新增或更新的文档章节,包括
与 SQL 的比较,这对熟悉 SQL 但仍在学习 pandas 的用户应该很有用。
与 R 的比较,将 R 的习惯用法转换为 pandas。
提升性能,使用
eval/query
提升 pandas 性能的方法。
警告
在 0.13.0 版本中,Series
在内部进行了重构,不再是 ndarray
的子类,而是继承自 NDFrame
,类似于 pandas 的其他容器。这应该是一个透明的变更,只对 API 产生非常有限的影响。请参阅 内部重构
API 变更#
read_excel
现在支持在其sheetname
参数中使用整数来指定要读取的工作表索引 (GH 4301)。文本解析器现在将所有读作无穷大的内容(例如 “inf”, “Inf”, “-Inf”, “iNf” 等)视为无穷大。(GH 4220, GH 4219),这会影响到
read_table
,read_csv
等方法。感谢 @jtratner,
pandas
现在与 Python 2/3 兼容,无需使用 2to3。因此,pandas 现在更广泛地使用了迭代器。这还将 Benjamin Peterson 的six
库的重要部分引入到了 compat 中。(GH 4384, GH 4375, GH 4372)pandas.util.compat
和pandas.util.py3compat
已合并到pandas.compat
中。pandas.compat
现在包含许多允许 2/3 兼容性的函数。它包含 range, filter, map 和 zip 的列表和迭代器版本,以及其他用于 Python 3 兼容性的必要元素。lmap
,lzip
,lrange
和lfilter
都生成列表而不是迭代器,以便与numpy
、下标和pandas
构造函数兼容。(GH 4384, GH 4375, GH 4372)Series.get
使用负数索引器时现在返回与[]
相同的结果 (GH 4390)Index
和MultiIndex
处理元数据 (levels
,labels
和names
) 的方式发生了变化 (GH 4039)# previously, you would have set levels or labels directly >>> pd.index.levels = [[1, 2, 3, 4], [1, 2, 4, 4]] # now, you use the set_levels or set_labels methods >>> index = pd.index.set_levels([[1, 2, 3, 4], [1, 2, 4, 4]]) # similarly, for names, you can rename the object # but setting names is not deprecated >>> index = pd.index.set_names(["bob", "cranberry"]) # and all methods take an inplace kwarg - but return None >>> pd.index.set_names(["bob", "cranberry"], inplace=True)
现在,对
NDFrame
对象进行所有除法运算都是真除法 (truedivision),无论是否进行了未来导入。这意味着对 pandas 对象进行运算时默认将使用浮点除法,并返回一个浮点 dtype。您可以使用//
和floordiv
进行整数除法。整数除法
In [3]: arr = np.array([1, 2, 3, 4]) In [4]: arr2 = np.array([5, 3, 2, 1]) In [5]: arr / arr2 Out[5]: array([0, 0, 1, 4]) In [6]: pd.Series(arr) // pd.Series(arr2) Out[6]: 0 0 1 0 2 1 3 4 dtype: int64
真除法
In [7]: pd.Series(arr) / pd.Series(arr2) # no future import required Out[7]: 0 0.200000 1 0.666667 2 1.500000 3 4.000000 dtype: float64
如果将
downcast='infer'
传递给fillna/ffill/bfill
,则推断并向下转换 dtype (GH 4604)现在,所有 NDFrame 对象的
__nonzero__
将引发ValueError
,这恢复了 (GH 1073, GH 4633) 的行为。有关更详细的讨论,请参阅 gotchas。这可以防止对整个 pandas 对象进行布尔比较,因为这本质上是模糊的。所有这些情况都将引发
ValueError
。>>> df = pd.DataFrame({'A': np.random.randn(10), ... 'B': np.random.randn(10), ... 'C': pd.date_range('20130101', periods=10) ... }) ... >>> if df: ... pass ... Traceback (most recent call last): ... ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). >>> df1 = df >>> df2 = df >>> df1 and df2 Traceback (most recent call last): ... ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). >>> d = [1, 2, 3] >>> s1 = pd.Series(d) >>> s2 = pd.Series(d) >>> s1 and s2 Traceback (most recent call last): ... ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
为
NDFrame
对象添加了.bool()
方法,以便于评估单元素的布尔 Series>>> pd.Series([True]).bool() True >>> pd.Series([False]).bool() False >>> pd.DataFrame([[True]]).bool() True >>> pd.DataFrame([[False]]).bool() False
所有非 Index 的 NDFrame 对象(
Series
,DataFrame
,Panel
,Panel4D
,SparsePanel
等)现在都支持全部算术运算符和算术灵活方法 (add, sub, mul 等)。SparsePanel
不支持与非标量进行pow
或mod
运算。(GH 3765)Series
和DataFrame
现在有了mode()
方法,可以按轴/Series 计算统计众数。(GH 5367)链式赋值现在默认为在用户向副本赋值时发出警告。这可以通过选项
mode.chained_assignment
进行更改,允许的选项为raise/warn/None
。请参阅 文档。In [1]: dfc = pd.DataFrame({'A': ['aaa', 'bbb', 'ccc'], 'B': [1, 2, 3]}) In [2]: pd.set_option('chained_assignment', 'warn')
如果尝试这样做,将显示以下警告/异常。
In [3]: dfc.loc[0]['A'] = 1111
Traceback (most recent call last) ... SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead
以下是正确的赋值方法。
In [4]: dfc.loc[0, 'A'] = 11 In [5]: dfc Out[5]: A B 0 11 1 1 bbb 2 2 ccc 3
Panel.reindex
的调用签名如下Panel.reindex(items=None, major_axis=None, minor_axis=None, **kwargs)
以符合其他
NDFrame
对象。有关更多信息,请参阅 内部重构。
Series.argmin
和Series.argmax
现在是Series.idxmin
和Series.idxmax
的别名。它们返回最小或最大元素的索引。0.13.0 版本之前,它们返回的是最小/最大元素的位置。(GH 6214)
之前版本的弃用/变更#
这些是 0.12 或更早版本中宣布的变更,自 0.13.0 版本起生效。
移除已弃用的
Factor
(GH 3650)移除已弃用的
set_printoptions/reset_printoptions
(GH 3046)移除已弃用的
_verbose_info
(GH 3215)从
pandas.io.parsers
中移除已弃用的read_clipboard/to_clipboard/ExcelFile/ExcelWriter
(GH 3717) 这些功能现在在主 pandas 命名空间中作为函数提供(例如pd.read_clipboard
)tupleize_cols
对于to_csv
和read_csv
现在默认为False
。在 0.12 中已有明确警告 (GH 3604)display.max_seq_len
的默认值现在是 100,而不是None
。这会在各种地方激活长序列的截断显示 (“…”)。(GH 3391)
弃用#
在 0.13.0 中弃用
索引 API 变更#
在 0.13 版本之前,无法使用标签索引器 (.loc/.ix
) 设置某个轴索引中不包含的值。(GH 2578)。请参阅 文档
对于 Series
,这实际上是追加操作。
In [6]: s = pd.Series([1, 2, 3])
In [7]: s
Out[7]:
0 1
1 2
2 3
dtype: int64
In [8]: s[5] = 5.
In [9]: s
Out[9]:
0 1.0
1 2.0
2 3.0
5 5.0
dtype: float64
In [10]: dfi = pd.DataFrame(np.arange(6).reshape(3, 2),
....: columns=['A', 'B'])
....:
In [11]: dfi
Out[11]:
A B
0 0 1
1 2 3
2 4 5
这在以前会引发 KeyError
In [12]: dfi.loc[:, 'C'] = dfi.loc[:, 'A']
In [13]: dfi
Out[13]:
A B C
0 0 1 0
1 2 3 2
2 4 5 4
这就像 append
操作。
In [14]: dfi.loc[3] = 5
In [15]: dfi
Out[15]:
A B C
0 0 1 0
1 2 3 2
2 4 5 4
3 5 5 5
在任意轴上执行 Panel 设置操作会将输入与 Panel 对齐
In [20]: p = pd.Panel(np.arange(16).reshape(2, 4, 2),
....: items=['Item1', 'Item2'],
....: major_axis=pd.date_range('2001/1/12', periods=4),
....: minor_axis=['A', 'B'], dtype='float64')
....:
In [21]: p
Out[21]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to B
In [22]: p.loc[:, :, 'C'] = pd.Series([30, 32], index=p.items)
In [23]: p
Out[23]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 3 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to C
In [24]: p.loc[:, :, 'C']
Out[24]:
Item1 Item2
2001-01-12 30.0 32.0
2001-01-13 30.0 32.0
2001-01-14 30.0 32.0
2001-01-15 30.0 32.0
Float64Index API 变更#
添加了新的索引类型
Float64Index
。在创建索引时传递浮点值会自动创建此类型。这实现了纯粹基于标签的切片范例,使得[]、ix、loc
对于标量索引和切片的操作完全一致。(GH 263)默认情况下,构造适用于浮点类型值。
In [16]: index = pd.Index([1.5, 2, 3, 4.5, 5]) In [17]: index Out[17]: Index([1.5, 2.0, 3.0, 4.5, 5.0], dtype='float64') In [18]: s = pd.Series(range(5), index=index) In [19]: s Out[19]: 1.5 0 2.0 1 3.0 2 4.5 3 5.0 4 dtype: int64
[]、.ix、.loc
的标量选择将始终基于标签。整数将匹配相等的浮点索引(例如3
等同于3.0
)In [20]: s[3] Out[20]: 2 In [21]: s.loc[3] Out[21]: 2
唯一的基于位置的索引是通过
iloc
In [22]: s.iloc[3] Out[22]: 3
未找到的标量索引将引发
KeyError
切片对于
[]、ix、loc
始终基于索引的值,对于iloc
始终基于位置In [23]: s[2:4] Out[23]: 2.0 1 3.0 2 dtype: int64 In [24]: s.loc[2:4] Out[24]: 2.0 1 3.0 2 dtype: int64 In [25]: s.iloc[2:4] Out[25]: 3.0 2 4.5 3 dtype: int64
在浮点索引中,允许使用浮点数进行切片
In [26]: s[2.1:4.6] Out[26]: 3.0 2 4.5 3 dtype: int64 In [27]: s.loc[2.1:4.6] Out[27]: 3.0 2 4.5 3 dtype: int64
其他索引类型的索引保持不变(并且
[]、ix
支持位置回退),但非Float64Index
的索引上使用浮点数进行切片现在会引发TypeError
。In [1]: pd.Series(range(5))[3.5] TypeError: the label [3.5] is not a proper indexer for this index type (Int64Index) In [1]: pd.Series(range(5))[3.5:4.5] TypeError: the slice start [3.5] is not a proper indexer for this index type (Int64Index)
在未来的版本中,使用标量浮点索引器将被弃用,但目前仍允许使用。
In [3]: pd.Series(range(5))[3.0] Out[3]: 3
HDFStore API 变更#
查询格式变更。现在支持更像字符串的查询格式。请参阅 文档。
In [28]: path = 'test.h5' In [29]: dfq = pd.DataFrame(np.random.randn(10, 4), ....: columns=list('ABCD'), ....: index=pd.date_range('20130101', periods=10)) ....: In [30]: dfq.to_hdf(path, key='dfq', format='table', data_columns=True)
使用布尔表达式,支持内联函数评估。
In [31]: pd.read_hdf(path, 'dfq', ....: where="index>Timestamp('20130104') & columns=['A', 'B']") ....: Out[31]: A B 2013-01-05 -0.424972 0.567020 2013-01-06 -0.673690 0.113648 2013-01-07 0.404705 0.577046 2013-01-08 -0.370647 -1.157892 2013-01-09 1.075770 -0.109050 2013-01-10 0.357021 -0.674600
使用内联列引用
In [32]: pd.read_hdf(path, 'dfq', ....: where="A>0 or C>0") ....: Out[32]: A B C D 2013-01-01 0.469112 -0.282863 -1.509059 -1.135632 2013-01-02 1.212112 -0.173215 0.119209 -1.044236 2013-01-04 0.721555 -0.706771 -1.039575 0.271860 2013-01-05 -0.424972 0.567020 0.276232 -1.087401 2013-01-07 0.404705 0.577046 -1.715002 -1.039268 2013-01-09 1.075770 -0.109050 1.643563 -1.469388 2013-01-10 0.357021 -0.674600 -1.776904 -0.968914
format
关键字现在取代了table
关键字;允许的值为fixed(f)
或table(t)
,与 0.13.0 之前版本的默认值相同,例如put
意味着fixed
格式,append
意味着table
格式。此默认格式可以通过设置选项io.hdf.default_format
来更改。In [33]: path = 'test.h5' In [34]: df = pd.DataFrame(np.random.randn(10, 2)) In [35]: df.to_hdf(path, key='df_table', format='table') In [36]: df.to_hdf(path, key='df_table2', append=True) In [37]: df.to_hdf(path, key='df_fixed') In [38]: with pd.HDFStore(path) as store: ....: print(store) ....: <class 'pandas.io.pytables.HDFStore'> File path: test.h5
显著提升了表写入性能
处理表格式中传递的
Series
(GH 4330)添加了
is_open
属性以指示底层文件句柄是否打开;关闭的存储现在在查看时将报告 ‘CLOSED’(而不是引发错误)(GH 4409)关闭
HDFStore
实例现在会关闭该实例,但只有当所有打开的句柄(由PyTables
计数)的引用计数为 0 时,才会关闭实际文件。本质上,您有一个由变量引用的HDFStore
本地实例。一旦您关闭它,它将报告已关闭。其他引用(指向同一文件)将继续操作,直到它们本身被关闭。在已关闭的文件上执行操作将引发ClosedFileError
In [39]: path = 'test.h5' In [40]: df = pd.DataFrame(np.random.randn(10, 2)) In [41]: store1 = pd.HDFStore(path) In [42]: store2 = pd.HDFStore(path) In [43]: store1.append('df', df) In [44]: store2.append('df2', df) In [45]: store1 Out[45]: <class 'pandas.io.pytables.HDFStore'> File path: test.h5 In [46]: store2 Out[46]: <class 'pandas.io.pytables.HDFStore'> File path: test.h5 In [47]: store1.close() In [48]: store2 Out[48]: <class 'pandas.io.pytables.HDFStore'> File path: test.h5 In [49]: store2.close() In [50]: store2 Out[50]: <class 'pandas.io.pytables.HDFStore'> File path: test.h5
移除了
_quiet
属性,如果在从表中检索重复行时,将替换为DuplicateWarning
(GH 4367)从
open
中移除了warn
参数。相反,如果您尝试对已打开的文件句柄使用mode='w'
,将引发PossibleDataLossError
异常 (GH 4367)在
append
中添加关键字dropna=True
以更改是否不写入所有 NaN 行到存储(默认值为True
,即不写入所有 NaN 行),也可以通过选项io.hdf.dropna_table
设置 (GH 4625)传递存储创建参数;可用于支持内存存储
DataFrame 表示变更#
DataFrame
的 HTML 和纯文本表示现在在超出一定大小时显示表格的截断视图,而不是切换到简短信息视图 (GH 4886, GH 5550)。这使得随着 DataFrame 变大,其表示更加一致。

要获取信息视图,请调用 DataFrame.info()
。如果您希望大型 DataFrame 的表示为信息视图,可以通过运行 set_option('display.large_repr', 'info')
来设置。
增强功能#
df.to_clipboard()
学会了一个新的excel
关键字,允许您将 df 数据直接粘贴到 Excel 中(默认启用)。(GH 5070)。read_html
现在引发URLError
,而不是捕获并引发ValueError
(GH 4303, GH 4305)为
read_clipboard()
和to_clipboard()
添加了测试 (GH 4282)剪贴板功能现在支持 PySide (GH 4282)
在 plot 参数包含重叠的颜色和样式参数时,添加了更具信息量的错误消息 (GH 4402)
to_dict
现在接受records
作为可能的输出类型。返回一个以列为键的字典数组。(GH 4936)在 get_dummies (GH 4446) 中处理
NaN
,使用dummy_na
参数# previously, nan was erroneously counted as 2 here # now it is not counted at all In [51]: pd.get_dummies([1, 2, np.nan]) Out[51]: 1.0 2.0 0 True False 1 False True 2 False False # unless requested In [52]: pd.get_dummies([1, 2, np.nan], dummy_na=True) Out[52]: 1.0 2.0 NaN 0 True False False 1 False True False 2 False False True
timedelta64[ns]
操作。请参阅 文档。警告
大多数这些操作需要
numpy >= 1.7
使用新的顶级函数
to_timedelta
,您可以将标准 timedelta 格式(由to_csv
生成)的标量或数组转换为 timedelta 类型(np.timedelta64
,单位为nanoseconds
)。In [53]: pd.to_timedelta('1 days 06:05:01.00003') Out[53]: Timedelta('1 days 06:05:01.000030') In [54]: pd.to_timedelta('15.5us') Out[54]: Timedelta('0 days 00:00:00.000015500') In [55]: pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan']) Out[55]: TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015500', NaT], dtype='timedelta64[ns]', freq=None) In [56]: pd.to_timedelta(np.arange(5), unit='s') Out[56]: TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02', '0 days 00:00:03', '0 days 00:00:04'], dtype='timedelta64[ns]', freq=None) In [57]: pd.to_timedelta(np.arange(5), unit='d') Out[57]: TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq=None)
dtype 为
timedelta64[ns]
的 Series 现在可以被另一个timedelta64[ns]
对象整除,或 astype 转换为float64
dtype 的 Series。这是频率转换。详见文档。In [58]: import datetime In [59]: td = pd.Series(pd.date_range('20130101', periods=4)) - pd.Series( ....: pd.date_range('20121201', periods=4)) ....: In [60]: td[2] += np.timedelta64(datetime.timedelta(minutes=5, seconds=3)) In [61]: td[3] = np.nan In [62]: td Out[62]: 0 31 days 00:00:00 1 31 days 00:00:00 2 31 days 00:05:03 3 NaT dtype: timedelta64[ns]
# to days In [63]: td / np.timedelta64(1, 'D') Out[63]: 0 31.000000 1 31.000000 2 31.003507 3 NaN dtype: float64 In [64]: td.astype('timedelta64[D]') Out[64]: 0 31.0 1 31.0 2 31.0 3 NaN dtype: float64 # to seconds In [65]: td / np.timedelta64(1, 's') Out[65]: 0 2678400.0 1 2678400.0 2 2678703.0 3 NaN dtype: float64 In [66]: td.astype('timedelta64[s]') Out[66]: 0 2678400.0 1 2678400.0 2 2678703.0 3 NaN dtype: float64
将
timedelta64[ns]
Series 除以或乘以整数或整数 SeriesIn [63]: td * -1 Out[63]: 0 -31 days +00:00:00 1 -31 days +00:00:00 2 -32 days +23:54:57 3 NaT dtype: timedelta64[ns] In [64]: td * pd.Series([1, 2, 3, 4]) Out[64]: 0 31 days 00:00:00 1 62 days 00:00:00 2 93 days 00:15:09 3 NaT dtype: timedelta64[ns]
绝对
DateOffset
对象现在可以等同于timedeltas
使用In [65]: from pandas import offsets In [66]: td + offsets.Minute(5) + offsets.Milli(5) Out[66]: 0 31 days 00:05:00.005000 1 31 days 00:05:00.005000 2 31 days 00:10:03.005000 3 NaT dtype: timedelta64[ns]
timedelta 现在支持 Fillna
In [67]: td.fillna(pd.Timedelta(0)) Out[67]: 0 31 days 00:00:00 1 31 days 00:00:00 2 31 days 00:05:03 3 0 days 00:00:00 dtype: timedelta64[ns] In [68]: td.fillna(datetime.timedelta(days=1, seconds=5)) Out[68]: 0 31 days 00:00:00 1 31 days 00:00:00 2 31 days 00:05:03 3 1 days 00:00:05 dtype: timedelta64[ns]
您可以在 timedelta 上执行数值归约运算。
In [69]: td.mean() Out[69]: Timedelta('31 days 00:01:41') In [70]: td.quantile(.1) Out[70]: Timedelta('31 days 00:00:00')
plot(kind='kde')
现在接受可选参数bw_method
和ind
,分别传递给 scipy.stats.gaussian_kde() (适用于 scipy >= 0.11.0) 用于设置带宽,以及传递给 gkde.evaluate() 用于指定评估索引。详见 scipy 文档。(GH 4298)DataFrame 构造函数现在接受 numpy 掩码记录数组(GH 3478)
新的向量化字符串方法
extract
更方便地返回正则表达式匹配项。In [71]: pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\\d)') Out[71]: 0 0 1 1 2 2 NaN
不匹配的元素返回
NaN
。提取具有多个组的正则表达式会返回一个 DataFrame,其中每组占一列。In [72]: pd.Series(['a1', 'b2', 'c3']).str.extract('([ab])(\\d)') Out[72]: 0 1 0 a 1 1 b 2 2 NaN NaN
不匹配的元素返回一整行
NaN
。因此,一个包含混乱字符串的 Series 可以被“转换”为一个索引相同、包含清理后或更有用字符串的 Series 或 DataFrame,而无需使用get()
访问元组或re.match
对象。命名组,如
In [73]: pd.Series(['a1', 'b2', 'c3']).str.extract( ....: '(?P<letter>[ab])(?P<digit>\\d)') ....: Out[73]: letter digit 0 a 1 1 b 2 2 NaN NaN
以及可选组也可以使用。
In [74]: pd.Series(['a1', 'b2', '3']).str.extract( ....: '(?P<letter>[ab])?(?P<digit>\\d)') ....: Out[74]: letter digit 0 a 1 1 b 2 2 NaN 3
read_stata
现在支持 Stata 13 格式(GH 4291)read_fwf
现在可以根据文件的前 100 行推断列规范,前提是数据使用提供的分隔符正确分隔并对齐列(GH 4488)。支持纳秒级时间作为偏移量
警告
这些操作需要
numpy >= 1.7
秒及以下范围的 Period 转换已重写并扩展至纳秒。现在可以使用纳秒范围的 Period。
In [79]: pd.date_range('2013-01-01', periods=5, freq='5N') Out[79]: DatetimeIndex([ '2013-01-01 00:00:00', '2013-01-01 00:00:00.000000005', '2013-01-01 00:00:00.000000010', '2013-01-01 00:00:00.000000015', '2013-01-01 00:00:00.000000020'], dtype='datetime64[ns]', freq='5N')
或以频率作为偏移量
In [75]: pd.date_range('2013-01-01', periods=5, freq=pd.offsets.Nano(5)) Out[75]: DatetimeIndex([ '2013-01-01 00:00:00', '2013-01-01 00:00:00.000000005', '2013-01-01 00:00:00.000000010', '2013-01-01 00:00:00.000000015', '2013-01-01 00:00:00.000000020'], dtype='datetime64[ns]', freq='5ns')
Timestamps 可以在纳秒范围内修改
In [76]: t = pd.Timestamp('20130101 09:01:02') In [77]: t + pd.tseries.offsets.Nano(123) Out[77]: Timestamp('2013-01-01 09:01:02.000000123')
DataFrame 的新方法
isin
可以很好地配合布尔索引。传入isin
的参数(用于与 DataFrame 比较的值)可以是 DataFrame、Series、dict 或值数组。详见文档。获取满足任一条件的行
In [78]: dfi = pd.DataFrame({'A': [1, 2, 3, 4], 'B': ['a', 'b', 'f', 'n']}) In [79]: dfi Out[79]: A B 0 1 a 1 2 b 2 3 f 3 4 n In [80]: other = pd.DataFrame({'A': [1, 3, 3, 7], 'B': ['e', 'f', 'f', 'e']}) In [81]: mask = dfi.isin(other) In [82]: mask Out[82]: A B 0 True False 1 False False 2 True True 3 False False In [83]: dfi[mask.any(axis=1)] Out[83]: A B 0 1 a 2 3 f
Series
现在支持to_frame
方法,将其转换为单列 DataFrame(GH 5164)此处列出的所有 R 数据集 http://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html 现在可以加载到 pandas 对象中
# note that pandas.rpy was deprecated in v0.16.0 import pandas.rpy.common as com com.load_data('Titanic')
DatetimeIndex
现在已包含在 API 文档中,详见文档添加了 PySide 对 qtpandas DataFrameModel 和 DataFrameWidget 的支持。
Python csv 解析器现在支持 usecols(GH 4335)
频率增加了几个新的偏移量
DataFrame 有了一个新方法
interpolate
,类似于 Series 的方法(GH 4434, GH 1892)In [84]: df = pd.DataFrame({'A': [1, 2.1, np.nan, 4.7, 5.6, 6.8], ....: 'B': [.25, np.nan, np.nan, 4, 12.2, 14.4]}) ....: In [85]: df.interpolate() Out[85]: A B 0 1.0 0.25 1 2.1 1.50 2 3.4 2.75 3 4.7 4.00 4 5.6 12.20 5 6.8 14.40
此外,
interpolate
的method
参数已扩展,包括'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric', 'krogh', 'piecewise_polynomial', 'pchip', 'polynomial', 'spline'
。新方法需要 scipy。有关各种方法何时适用,请查阅 Scipy 参考指南和文档。详见文档。interpolate 现在还接受
limit
关键字参数。这类似于fillna
的 limitIn [86]: ser = pd.Series([1, 3, np.nan, np.nan, np.nan, 11]) In [87]: ser.interpolate(limit=2) Out[87]: 0 1.0 1 3.0 2 5.0 3 7.0 4 NaN 5 11.0 dtype: float64
添加了
wide_to_long
面板数据便捷函数。详见文档。In [88]: np.random.seed(123) In [89]: df = pd.DataFrame({"A1970" : {0 : "a", 1 : "b", 2 : "c"}, ....: "A1980" : {0 : "d", 1 : "e", 2 : "f"}, ....: "B1970" : {0 : 2.5, 1 : 1.2, 2 : .7}, ....: "B1980" : {0 : 3.2, 1 : 1.3, 2 : .1}, ....: "X" : dict(zip(range(3), np.random.randn(3))) ....: }) ....: In [90]: df["id"] = df.index In [91]: df Out[91]: A1970 A1980 B1970 B1980 X id 0 a d 2.5 3.2 -1.085631 0 1 b e 1.2 1.3 0.997345 1 2 c f 0.7 0.1 0.282978 2 In [92]: pd.wide_to_long(df, ["A", "B"], i="id", j="year") Out[92]: X A B id year 0 1970 -1.085631 a 2.5 1 1970 0.997345 b 1.2 2 1970 0.282978 c 0.7 0 1980 -1.085631 d 3.2 1 1980 0.997345 e 1.3 2 1980 0.282978 f 0.1
实验性#
新的
eval()
函数在后台使用numexpr
实现表达式评估。这使得涉及大型 DataFrame/Series 的复杂表达式的评估速度大大加快。例如:In [93]: nrows, ncols = 20000, 100 In [94]: df1, df2, df3, df4 = [pd.DataFrame(np.random.randn(nrows, ncols)) ....: for _ in range(4)] ....:
# eval with NumExpr backend In [95]: %timeit pd.eval('df1 + df2 + df3 + df4') 6.88 ms +- 275 us per loop (mean +- std. dev. of 7 runs, 100 loops each)
# pure Python evaluation In [96]: %timeit df1 + df2 + df3 + df4 6.5 ms +- 286 us per loop (mean +- std. dev. of 7 runs, 100 loops each)
有关更多详细信息,请参阅文档
类似于
pandas.eval
,DataFrame
有一个新的DataFrame.eval
方法,用于在DataFrame
的上下文中评估表达式。例如:In [97]: df = pd.DataFrame(np.random.randn(10, 2), columns=['a', 'b']) In [98]: df.eval('a + b') Out[98]: 0 -0.685204 1 1.589745 2 0.325441 3 -1.784153 4 -0.432893 5 0.171850 6 1.895919 7 3.065587 8 -0.092759 9 1.391365 dtype: float64
添加了
query()
方法,允许您使用几乎与 Python 语法相同的自然查询语法选择DataFrame
的元素。例如:In [99]: n = 20 In [100]: df = pd.DataFrame(np.random.randint(n, size=(n, 3)), columns=['a', 'b', 'c']) In [101]: df.query('a < b < c') Out[101]: a b c 11 1 5 8 15 8 16 19
选择
df
中a < b < c
评估结果为True
的所有行。有关更多详细信息,请参阅文档。pd.read_msgpack()
和pd.to_msgpack()
现在是序列化任意 pandas(和 python 对象)的受支持方法,使用轻量级可移植二进制格式。详见文档警告
由于这是一个实验性库(EXPERIMENTAL LIBRARY),存储格式在未来版本之前可能不稳定。
df = pd.DataFrame(np.random.rand(5, 2), columns=list('AB')) df.to_msgpack('foo.msg') pd.read_msgpack('foo.msg') s = pd.Series(np.random.rand(5), index=pd.date_range('20130101', periods=5)) pd.to_msgpack('foo.msg', df, s) pd.read_msgpack('foo.msg')
您可以传递
iterator=True
以迭代解包结果for o in pd.read_msgpack('foo.msg', iterator=True): print(o)
pandas.io.gbq
提供了一种简单的方式,通过 pandas DataFrame 从 Google 的 BigQuery 数据集提取数据并加载数据。BigQuery 是一种高性能的类 SQL 数据库服务,对于对极其大型数据集执行临时查询非常有用。详见文档from pandas.io import gbq # A query to select the average monthly temperatures in the # in the year 2000 across the USA. The dataset, # publicata:samples.gsod, is available on all BigQuery accounts, # and is based on NOAA gsod data. query = """SELECT station_number as STATION, month as MONTH, AVG(mean_temp) as MEAN_TEMP FROM publicdata:samples.gsod WHERE YEAR = 2000 GROUP BY STATION, MONTH ORDER BY STATION, MONTH ASC""" # Fetch the result set for this query # Your Google BigQuery Project ID # To find this, see your dashboard: # https://console.developers.google.com/iam-admin/projects?authuser=0 projectid = 'xxxxxxxxx' df = gbq.read_gbq(query, project_id=projectid) # Use pandas to process and reshape the dataset df2 = df.pivot(index='STATION', columns='MONTH', values='MEAN_TEMP') df3 = pd.concat([df2.min(), df2.mean(), df2.max()], axis=1, keys=["Min Tem", "Mean Temp", "Max Temp"])
结果 DataFrame 为
> df3 Min Tem Mean Temp Max Temp MONTH 1 -53.336667 39.827892 89.770968 2 -49.837500 43.685219 93.437932 3 -77.926087 48.708355 96.099998 4 -82.892858 55.070087 97.317240 5 -92.378261 61.428117 102.042856 6 -77.703334 65.858888 102.900000 7 -87.821428 68.169663 106.510714 8 -89.431999 68.614215 105.500000 9 -86.611112 63.436935 107.142856 10 -78.209677 56.880838 92.103333 11 -50.125000 48.861228 94.996428 12 -50.332258 42.286879 94.396774
警告
要使用此模块,您需要一个 BigQuery 帐户。详细信息请参阅 <https://cloud.google.com/products/big-query>。
截至 2013 年 10 月 10 日,Google 的 API 存在一个错误,阻止结果集超过 100,000 行。计划在 2013 年 10 月 14 日那一周发布补丁。
内部重构#
在 0.13.0 版本中,进行了一次主要的重构,主要是将 Series
子类化自 NDFrame
,后者是当前 DataFrame
和 Panel
的基类,以统一方法和行为。Series 以前直接子类化自 ndarray
。(GH 4080, GH 3862, GH 816)
警告
与 < 0.13.0 版本相比,存在两个潜在的不兼容性:
之前,如果将
Series
作为参数传递给某些 numpy 函数,这些函数会返回一个Series
。这似乎只影响np.ones_like
,np.empty_like
,np.diff
和np.where
。现在这些函数返回ndarrays
。In [102]: s = pd.Series([1, 2, 3, 4])
Numpy 用法
In [103]: np.ones_like(s) Out[103]: array([1, 1, 1, 1]) In [104]: np.diff(s) Out[104]: array([1, 1, 1]) In [105]: np.where(s > 1, s, np.nan) Out[105]: array([nan, 2., 3., 4.])
Pandonic 用法
In [106]: pd.Series(1, index=s.index) Out[106]: 0 1 1 1 2 1 3 1 dtype: int64 In [107]: s.diff() Out[107]: 0 NaN 1 1.0 2 1.0 3 1.0 dtype: float64 In [108]: s.where(s > 1) Out[108]: 0 NaN 1 2.0 2 3.0 3 4.0 dtype: float64
将
Series
直接传递给期望ndarray
类型的 cython 函数将不再直接工作,您必须传递Series.values
。详见提升性能Series(0.5)
之前会返回标量0.5
,现在则会返回一个包含 1 个元素的Series
此更改导致
rpy2<=2.3.8
不兼容。已针对 rpy2 开启了一个 Issue,并在 GH 5698 中详细介绍了临时解决方案。感谢 @JanSchulz。
0.13 版本之前创建的 pickle 文件兼容性得到保留。这些文件必须使用
pd.read_pickle
进行反序列化,详见Pickling。重构 series.py/frame.py/panel.py,将通用代码移至 generic.py
添加了
_setup_axes
用于创建通用 NDFrame 结构移动的方法
from_axes,_wrap_array,axes,ix,loc,iloc,shape,empty,swapaxes,transpose,pop
__iter__,keys,__contains__,__len__,__neg__,__invert__
convert_objects,as_blocks,as_matrix,values
__getstate__,__setstate__
(兼容性保留在 frame/panel 中)__getattr__,__setattr__
_indexed_same,reindex_like,align,where,mask
fillna,replace
(Series
的 replace 现在与DataFrame
保持一致)filter
(也添加了 axis 参数以在不同轴上选择性过滤)reindex,reindex_axis,take
truncate
(移至NDFrame
的一部分)
这些是 API 变更,使得
Panel
与DataFrame
更一致在
Panel
上指定相同轴的swapaxes
现在返回一个副本支持通过属性访问进行设置
filter 支持与原始
DataFrame
filter 相同的 API
调用不带参数的 Reindex 现在将返回输入对象的副本
TimeSeries
现在是Series
的别名。属性is_time_series
可用于区分(如果需要)重构 Sparse 对象以使用 BlockManager
在内部创建了一个新的块类型,
SparseBlock
,它可以容纳多种 dtype 且不可合并。SparseSeries
和SparseDataFrame
现在从其层次结构(Series/DataFrame)继承更多方法,并且不再继承自SparseArray
(后者现在是SparseBlock
的对象)Sparse 套件现在支持与非稀疏数据的集成。非浮点型稀疏数据是可支持的(部分实现)
DataFrame 内的稀疏结构操作应保留稀疏性,合并类型操作将转换为密集格式(然后再转回稀疏),因此效率可能较低
启用
SparseSeries
的 setitem 操作,用于布尔、整数和切片索引SparsePanels
的实现没有改变(例如,未使用 BlockManager,需要改进)
向 Series/DataFrame 添加了
ftypes
方法,类似于dtypes
,但指示底层是否为稀疏/密集(以及 dtype)所有
NDFrame
对象现在可以使用__finalize__()
指定要从现有对象传播到新对象的各种值(例如,Series
中的name
现在将更自动地跟随)内部类型检查现在通过一组生成的类完成,允许使用
isinstance(value, klass)
而无需直接导入 klass,感谢 @jtratnerSeries 更新中的 bug,其中父 frame 未根据更改(GH 4080)或类型(GH 3217)更新其缓存,fillna(GH 3386)
将
Series.reindex
重构到 core/generic.py(GH 4604, GH 4618),允许在 Series 上使用method=
进行 reindexingSeries.copy
不再接受order
参数,并且现在与NDFrame
copy 保持一致将
rename
方法重构到 core/generic.py;修复了Series.rename
的 bug(GH 4605),并为Panel
添加了具有相同签名的rename
方法将
clip
方法重构到 core/generic.py(GH 4798)将
_get_numeric_data/_get_bool_data
重构到 core/generic.py,使 Series/Panel 具备此功能Series
(用于索引)/Panel
(用于项目)现在允许通过属性访问其元素(GH 1903)In [109]: s = pd.Series([1, 2, 3], index=list('abc')) In [110]: s.b Out[110]: 2 In [111]: s.a = 5 In [112]: s Out[112]: a 5 b 2 c 3 dtype: int64
Bug 修复#
HDFStore
追加时,如果块顺序不同,会抛出无效的
TypeError
而非ValueError
(GH 4096)read_hdf
未遵循传入的mode
(GH 4504)追加一个长度为 0 的表现在可以正确工作(GH 4273)
to_hdf
在同时传递append
和table
两个参数时会抛出异常(GH 4584)从一个包含跨 dtype 重复列的 store 中读取时会抛出异常(GH 4767)
修复了当列名不是字符串时未正确抛出
ValueError
的 bug(GH 4956)长度为零的以 Fixed 格式写入的 Series 未正确反序列化。(GH 4708)
修复了 pyt3 上的解码性能问题(GH 5441)
存储 MultiIndex 之前验证级别(GH 5527)
正确处理带有 Panel 的
data_columns
(GH 5717)
修复了 tslib.tz_convert(vals, tz1, tz2) 中的 bug:它在尝试访问 trans[pos + 1] 时可能抛出 IndexError 异常(GH 4496)
修复了
PeriodIndex.map
中使用str
会返回索引的 str 表示形式的 bug(GH 4136)修复了使用自定义 matplotlib 默认颜色时测试失败
test_time_series_plot_color_with_empty_kwargs
的问题(GH 4345)修复了 stata IO 测试的运行。现在使用临时文件进行写入(GH 4353)
修复了
DataFrame.sum
对于整数值 frame 比DataFrame.mean
慢的 bug(GH 4365)read_html
测试现在支持 Python 2.6(GH 4351)修复了
network
测试抛出NameError
的 bug,原因是局部变量未定义(GH 4381)在
to_json
中,如果传入的orient
会由于重复索引导致数据丢失,则抛出异常(GH 4359)在
to_json
中,修复了日期处理,使其默认时间戳为毫秒,如文档字符串所述(GH 4362)。JSON NaT 处理已修复,NaT 现在序列化为
null
(GH 4498)修复了 JSON 对象键中可转义字符的 JSON 处理(GH 4593)
修复了在
na_values=None
时传递keep_default_na=False
的 bug(GH 4318)修复了在具有重复列和混合 dtype 的 DataFrame 上,
values
抛出错误的 bug,该问题在(GH 4377)中出现修复了在
orient='split'
时,read_json
中重复列和类型转换的 bug(GH 4377)修复了当区域设置使用非“.”的小数分隔符时,在编码/解码某些值时 JSON bug 抛出异常的问题。(GH 4918)
修复了使用
PeriodIndex
进行.iat
索引的 bug(GH 4390)修复了
PeriodIndex
与自身连接时返回新实例而非相同实例的问题(GH 4379);同时为其他索引类型添加了相应的测试修复了在使用 usecols 参数时,CSV cparser 将所有 dtype 转换为对象的 bug(GH 3192)
修复了合并块时,生成的 DataFrame 的 _ref_locs 部分设置不正确的 bug(GH 4403)
修复了使用顶级 matplotlib API 调用 hist 子图时,子图被覆盖的 bug(GH 4408)
修复了 py3 兼容性问题,即 bytes 被 repr 为元组(GH 4455)
修复了如果 item 命名为 'a' 时 Panel 属性命名冲突的问题(GH 3440)
修复了绘图时重复索引会抛出异常的问题(GH 4486)
修复了
xs
中 Panel 切片返回不正确暗淡对象的 bug(GH 4016)修复了 Panel 转置框架的赋值问题 (GH 3830)
当使用 Panel 进行索引设置,且值为需要对齐的 Panel 时引发错误 (GH 3777)
修复了对具有多个 dtype 的重复 MultiIndex 进行排序时出现的问题 (GH 4516)
修复了
DataFrame.set_values
中的错误,该错误导致在扩展索引时丢失名称属性 (GH 3742, GH 4039)修复了在
MultiIndex
上未经验证即可设置单独的names
、levels
和labels
时出现的问题 (GH 3714, GH 4039)修复了 pivot_table 中的问题 (GH 3334)。如果 values 是索引,则不会计算 margins。
修复了对 datetime 执行操作时,右侧为
np.timedelta64
或np.offsets.DateOffset
的错误 (GH 4532)修复了 series/datetimeindex 与
np.timedelta64
进行算术运算时行为不一致的问题 (GH 4134),以及 NumPy 1.6 中 timedelta 的错误 (GH 4135)修复了 PY3 Windows 环境下
pd.read_clipboard
中的错误 (GH 4561);解码不正确如果 code 参数超出范围,
tslib.get_period_field()
和tslib.get_period_field_arr()
现在会引发错误 (GH 4519, GH 4520)修复了对空 series 进行布尔索引时丢失索引名称的问题 (GH 4235),infer_dtype 现在可处理空数组。
修复了使用多个轴进行重新索引的问题;如果轴匹配未替换当前轴,则可能导致延迟频率推断问题 (GH 3317)
修复了
DataFrame.apply
重新引发异常不正确的问题(导致原始堆栈跟踪被截断)。修复了使用
ix/loc
和非唯一选择器进行选择的问题 (GH 4619)修复了使用 iloc/loc 进行赋值时涉及现有列 dtype 更改的问题 (GH 4312, GH 5702),core/indexing 中的内部 setitem_with_indexer 现在使用 Block.setitem
修复了 csv_import 中浮点数千位分隔符处理不正确的错误 (GH 4322)
修复了许多 DateOffset 未正确使用 CacheableOffset 的问题;这阻止了 DateOffset 被缓存 (GH 4609)
修复了 DataFrame 在左侧,list/tuple 在右侧的布尔比较问题 (GH 4576)
修复了对
Series/DataFrame
设置None
值时的错误/dtype 转换问题 (GH 4667)修复了
pd.read_stata
中基于传入的非默认编码进行解码的问题 (GH 4626)修复了
DataFrame.from_records
处理普通ndarray
的问题 (GH 4727)修复了
Index.rename
和MultiIndex.rename
等的一些不一致之处 (GH 4718, GH 4628)使用
iloc/loc
处理截面和重复索引时的错误 (GH 4726)to_csv
使用QUOTE_NONE
导致Exception
的错误 (GH 4328)Series 索引时,右侧长度不正确未引发错误的错误 (GH 2702)
MultiIndex 中,使用部分字符串选择作为 MultiIndex 的一部分时的错误 (GH 4758)
使用非唯一索引对索引进行重新索引时,现在会引发
ValueError
(GH 4746)使用
loc/ix
设置 MultiIndex 轴上的单个索引器和 NumPy 数组时的错误,与 (GH 3777) 相关iloc
使用切片索引失败的错误 (GH 4771)read_fwf
中没有 colspecs 或 width 时错误的错误消息 (GH 4774)修复了 Python 3 中使用
read_fwf
读取压缩文件的错误 (GH 3963)修复了重复索引和带 dtype 更改的赋值问题 (GH 4686)
修复了 Python 3 中将压缩文件读取为
bytes
而非str
的错误。简化了 Python 3 中产生字节的文件处理 (GH 3963, GH 4785)。修复了不同版本 matplotlib 中对数刻度条形图的 ticklocs/ticklabels 相关问题 (GH 4789)
抑制了与 repr() 发出的内部调用相关的 DeprecationWarning (GH 4391)
修复了使用
.loc
处理重复索引和重复选择器的问题 (GH 4825)修复了
DataFrame.sort_index
的一个问题,当按单列排序并为ascending
传递列表时,ascending
参数被解释为True
(GH 4839, GH 4846)修复了
Panel.tshift
不工作的问题。向Panel.shift
添加了freq
支持 (GH 4853)修复了 TextFileReader 在 Python 引擎 (即 PythonParser) 中,当 thousands != “,” 时的问题 (GH 4596)
使用 where 时,带有重复索引的 getitem 错误 (GH 4879)
修复类型推断代码将浮点列强制转换为 datetime 的问题 (GH 4601)
修复了
_ensure_numeric
未检查复数的问题 (GH 4902)修复了
convert_objects
处理 > 2 维数组的错误 (GH 4937)修复了
FrozenNDArray
和FrozenList
的字符串方法 (GH 4929)修复了在索引扩展场景中设置无效或超出范围值时的错误 (GH 4940)
空 Series 上 fillna 的测试 (GH 4346),感谢 @immerrr
修复了 read_csv Python 解析器中的 skiprows 选项 (GH 4382)
修复了在未明确传递 labels 时
cut
无法处理np.inf
级别的错误 (GH 3415)修复了
DatetimeIndex.union
中重叠检查错误 (GH 4564)修复了 csv_parser 中千位分隔符和日期解析器之间的冲突 (GH 4678)
修复了 dtypes 不相同时的追加问题(显示混合 float/np.datetime64 的错误)(GH 4993)
修复了 DateOffset 的 repr。kwds 中不再显示重复条目。删除了未使用的 offset 字段 (GH 4638)。
修复了 read_csv 使用 usecols 时错误的索引名称。仅适用于 C 解析器 (GH 4201)。
Timestamp
对象现在可以出现在与Series
或DataFrame
对象比较操作的左侧 (GH 4982)。修复了通过
iloc/loc
使用np.nan
进行索引时的错误 (GH 5016)修复了低内存 C 解析器在同一文件的不同块中创建不同类型的错误。现在强制转换为数值类型或引发警告 (GH 3866)。
修复了将
Series
重塑为其自身形状时引发TypeError
的错误 (GH 4554) 和其他重塑问题。使用
ix/loc
和混合 int/string 索引进行设置时的错误 (GH 4544)确保 series-series 布尔比较是基于标签的 (GH 4947)
使用 Timestamp 部分索引器进行多级索引时的错误 (GH 4294)
MultiIndex 构建全 nan 帧的测试/修复 (GH 4078)
修复了
read_html()
未正确推断带有逗号的表格值的错误 (GH 5029)修复了
read_html()
未提供返回表格的稳定顺序的错误 (GH 4770, GH 5029)。修复了
read_html()
在传递index_col=0
时解析不正确的错误 (GH 5066)。修复了
read_html()
未正确推断 header 类型的错误 (GH 5048)。修复了
DatetimeIndex
与PeriodIndex
连接导致栈溢出的错误 (GH 3899)。修复了
groupby
对象不允许绘图的错误 (GH 5102)。修复了
groupby
对象未进行列名 Tab 补全的错误 (GH 5102)。修复了
groupby.plot()
及相关方法多次复制图形的错误 (GH 5102)。fillna 时提供
object
dtype 的自动转换,相关 (GH 5103)修复了 option parser 清理过程中默认选项被覆盖的错误 (GH 5121)。
对于使用 list-like 进行
iloc
索引,list/ndarray 的处理方式相同 (GH 5006)修复了
MultiIndex.get_level_values()
处理缺失值的问题 (GH 5074)修复了 Timestamp() 使用 datetime64 输入时的边界检查问题 (GH 4065)
修复了
TestReadHtml
未调用正确的read_html()
函数的错误 (GH 5150)。修复了
NDFrame.replace()
的错误,该错误导致替换看起来(不正确地)使用了正则表达式 (GH 5143)。修复了 to_datetime 更友好的错误消息 (GH 4928)
确保在 travis-ci 上测试了不同的 locale (GH 4918)。还添加了一些用于获取 locale 和使用上下文管理器设置 locale 的实用工具。
构造函数中的复合 dtype 会引发
NotImplementedError
(GH 5191)比较重复帧的错误 (GH 4421) 相关
对重复帧进行 describe 的错误
to_datetime
使用 format 和coerce=True
未引发错误的错误 (GH 5195)loc
使用多个索引器和需要广播的 Series 作为右侧值进行设置时的错误 (GH 5206)修复了在
MultiIndex
上 inplace 设置 levels 或 labels 时,不会清除缓存的values
属性并因此返回错误values
的错误 (GH 5215)。修复了过滤分组的 DataFrame 或 Series 时未保持原始顺序的错误 (GH 4621)。
修复了 Period 使用工作日频率时,如果在非工作日则始终向前滚动的问题 (GH 5203)。
修复了 Excel 写入器中,带有重复列名的帧未正确写入的错误 (GH 5235)。
修复了
drop
和 Series 上非唯一索引的问题 (GH 5248)修复了 C 解析器中由于传递的名称多于文件中的列数而导致的段错误 (GH 5156)。
修复了
Series.isin
处理 date/time-like dtype 的问题 (GH 5021)C 和 Python 解析器现在可以处理更常见的 MultiIndex 列格式,该格式没有索引名称行 (GH 4702)
尝试将超出范围的日期用作对象 dtype 时的错误 (GH 5312)
尝试显示嵌入式 PandasObject 时的错误 (GH 5324)
允许 Timestamps 操作在结果超出范围时返回 datetime,相关 (GH 5312)
修复了
initObjToJSON()
的返回值/类型签名,使其与 numpy 的import_array()
兼容 (GH 5334, GH 5326)对 DataFrame 先进行 rename 再进行 set_index 时的错误 (GH 5344)
测试套件在测试图形时不再留下临时文件 (GH 5347)(感谢 @yarikoptic 发现了这个问题!)
修复了 win32 上的 html 测试 (GH 4580)。
确保
head/tail
是基于iloc
的 (GH 5370)修复了
PeriodIndex
字符串表示中存在 1 个或 2 个元素时的错误 (GH 5372)。GroupBy 方法
transform
和filter
可以用于具有重复(非唯一)索引的 Series 和 DataFrame (GH 4620)。修复了空 Series 在 repr 中不打印名称的问题 (GH 4651)
默认情况下,使测试在临时目录中创建临时文件 (GH 5419)。
pd.to_timedelta
处理标量时返回标量 (GH 5410)pd.to_timedelta
接受NaN
和NaT
,返回NaT
而非引发错误 (GH 5437)isnull
在处理较大 pandas 对象时的性能改进修复了各种使用与索引器长度不匹配的 1d ndarray 进行 setitem 的问题 (GH 5508)
MultiIndex 和
iloc
进行 getitem 时的错误 (GH 5528)Series 上的 delitem 错误 (GH 5542)
使用自定义函数且对象未变异时 apply 中的错误修复 (GH 5545)
使用
loc
从非唯一索引中选择时的错误 (GH 5553)当用户函数返回
None
时 groupby 返回不一致类型的错误 (GH 5592)解决 numpy 1.7.0 中
ndarray.item
错误地引发 IndexError 的回归问题 (GH 5666)对象重复索引结果为非唯一索引时的错误 (GH 5678)
fillna 使用 Series 和传递的 series/dict 时的错误 (GH 5703)
groupby transform 使用 datetime-like grouper 时的错误 (GH 5712)
PY3 中 MultiIndex 选择使用某些 key 时的错误 (GH 5725)
某些情况下不同 dtype 的行式拼接失败 (GH 5754)
贡献者#
共有 77 人为此版本贡献了补丁。姓名旁有“+”的人是首次贡献。
Agustín Herranz + (首次贡献)
Alex Gaudio + (首次贡献)
Alex Rothberg + (首次贡献)
Andreas Klostermann + (首次贡献)
Andreas Würl + (首次贡献)
Andy Hayden
Ben Alex + (首次贡献)
Benedikt Sauer + (首次贡献)
Brad Buran
Caleb Epstein + (首次贡献)
Chang She
Christopher Whelan
DSM + (首次贡献)
Dale Jung + (首次贡献)
Dan Birken
David Rasch + (首次贡献)
Dieter Vandenbussche
Gabi Davar + (首次贡献)
Garrett Drapala
Goyo + (首次贡献)
Greg Reda + (首次贡献)
Ivan Smirnov + (首次贡献)
Jack Kelly + (首次贡献)
Jacob Schaer + (首次贡献)
Jan Schulz + (首次贡献)
Jeff Tratner
Jeffrey Tratner
John McNamara + (首次贡献)
John W. O’Brien + (首次贡献)
Joris Van den Bossche
Justin Bozonier + (首次贡献)
Kelsey Jordahl
Kevin Stone
Kieran O’Mahony
Kyle Hausmann + (首次贡献)
Kyle Kelley + (首次贡献)
Kyle Meyer
Mike Kelly
Mortada Mehyar + (首次贡献)
Nick Foti + (首次贡献)
Olivier Harris + (首次贡献)
Ondřej Čertík + (首次贡献)
PKEuS
Phillip Cloud
Pierre Haessig + (首次贡献)
Richard T. Guy + (首次贡献)
Roman Pekar + (首次贡献)
Roy Hyunjin Han
Skipper Seabold
Sten + (首次贡献)
Thomas A Caswell + (首次贡献)
Thomas Kluyver
Tiago Requeijo + (首次贡献)
TomAugspurger
Trent Hauck
Valentin Haenel + (首次贡献)
Viktor Kerkez + (首次贡献)
Vincent Arel-Bundock
Wes McKinney
Wes Turner + (首次贡献)
Weston Renoud + (首次贡献)
Yaroslav Halchenko
Zach Dwiel + (首次贡献)
chapman siu + (首次贡献)
chappers + (首次贡献)
d10genes + (首次贡献)
danielballan
daydreamt + (首次贡献)
engstrom + (首次贡献)
jreback
monicaBee + (首次贡献)
prossahl + (首次贡献)
rockg + (首次贡献)
unutbu + (首次贡献)
westurner + (首次贡献)
y-p
zach powers