版本 0.16.0 (2015 年 3 月 22 日)#
这是继 0.15.2 之后的一个重要版本,包含少量 API 更改、一些新特性、增强功能、性能改进以及大量错误修复。我们建议所有用户升级到此版本。
主要亮点包括
DataFrame.assign
方法,请参阅此处Series.to_coo/from_coo
方法,用于与scipy.sparse
交互,请参阅此处对
Timedelta
进行了向后不兼容的更改,使其.seconds
属性与datetime.timedelta
一致,请参阅此处对
.loc
切片 API 进行了更改,使其与.ix
的行为一致,请参阅此处对
Categorical
构造函数中排序的默认值进行了更改,请参阅此处对
.str
访问器进行了增强,以使字符串操作更容易,请参阅此处pandas.tools.rplot
、pandas.sandbox.qtpandas
和pandas.rpy
模块已被弃用。对于相似或等效的功能,我们建议用户使用 seaborn、pandas-qt 和 rpy2 等外部包,请参阅此处
v0.16.0 版本新特性
新特性#
DataFrame assign#
受 dplyr 的 mutate
动词启发,DataFrame 新增了一个 assign()
方法。assign
的函数签名很简单,就是 **kwargs
。键是新字段的列名,值是要插入的值(例如,Series
或 NumPy 数组),或者是对 DataFrame
调用一个参数的函数。新值将被插入,并返回包含所有原始列和新列的整个 DataFrame。
In [1]: iris = pd.read_csv('data/iris.data')
In [2]: iris.head()
Out[2]:
SepalLength SepalWidth PetalLength PetalWidth Name
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
[5 rows x 5 columns]
In [3]: iris.assign(sepal_ratio=iris['SepalWidth'] / iris['SepalLength']).head()
Out[3]:
SepalLength SepalWidth PetalLength PetalWidth Name sepal_ratio
0 5.1 3.5 1.4 0.2 Iris-setosa 0.686275
1 4.9 3.0 1.4 0.2 Iris-setosa 0.612245
2 4.7 3.2 1.3 0.2 Iris-setosa 0.680851
3 4.6 3.1 1.5 0.2 Iris-setosa 0.673913
4 5.0 3.6 1.4 0.2 Iris-setosa 0.720000
[5 rows x 6 columns]
上面是插入预计算值的示例。我们也可以传入一个函数进行计算。
In [4]: iris.assign(sepal_ratio=lambda x: (x['SepalWidth']
...: / x['SepalLength'])).head()
...:
Out[4]:
SepalLength SepalWidth PetalLength PetalWidth Name sepal_ratio
0 5.1 3.5 1.4 0.2 Iris-setosa 0.686275
1 4.9 3.0 1.4 0.2 Iris-setosa 0.612245
2 4.7 3.2 1.3 0.2 Iris-setosa 0.680851
3 4.6 3.1 1.5 0.2 Iris-setosa 0.673913
4 5.0 3.6 1.4 0.2 Iris-setosa 0.720000
[5 rows x 6 columns]
assign
的强大之处在于它可以在链式操作中使用。例如,我们可以将 DataFrame 限定为萼片长度大于 5 的行,计算比例,然后绘图
In [5]: iris = pd.read_csv('data/iris.data')
In [6]: (iris.query('SepalLength > 5')
...: .assign(SepalRatio=lambda x: x.SepalWidth / x.SepalLength,
...: PetalRatio=lambda x: x.PetalWidth / x.PetalLength)
...: .plot(kind='scatter', x='SepalRatio', y='PetalRatio'))
...:
Out[6]: <Axes: xlabel='SepalRatio', ylabel='PetalRatio'>

与 scipy.sparse 的交互#
添加了 SparseSeries.to_coo()
和 SparseSeries.from_coo()
方法 (GH 8048),用于在 scipy.sparse.coo_matrix
实例之间进行转换(请参阅此处)。例如,给定一个带有 MultiIndex 的 SparseSeries,我们可以通过将行标签和列标签指定为索引级别来将其转换为 scipy.sparse.coo_matrix
s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan])
s.index = pd.MultiIndex.from_tuples([(1, 2, 'a', 0),
(1, 2, 'a', 1),
(1, 1, 'b', 0),
(1, 1, 'b', 1),
(2, 1, 'b', 0),
(2, 1, 'b', 1)],
names=['A', 'B', 'C', 'D'])
s
# SparseSeries
ss = s.to_sparse()
ss
A, rows, columns = ss.to_coo(row_levels=['A', 'B'],
column_levels=['C', 'D'],
sort_labels=False)
A
A.todense()
rows
columns
from_coo 方法是一个便捷方法,用于从 scipy.sparse.coo_matrix
创建 SparseSeries
from scipy import sparse
A = sparse.coo_matrix(([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])),
shape=(3, 4))
A
A.todense()
ss = pd.SparseSeries.from_coo(A)
ss
字符串方法增强#
以下新方法可以通过
.str
访问器调用,用于对每个值应用函数。此举旨在使其与标准字符串方法更加一致。(GH 9282, GH 9352, GH 9386, GH 9387, GH 9439)方法
isalnum()
isalpha()
isdigit()
isdigit()
isspace()
islower()
isupper()
istitle()
isnumeric()
isdecimal()
find()
rfind()
ljust()
rjust()
zfill()
In [7]: s = pd.Series(['abcd', '3456', 'EFGH']) In [8]: s.str.isalpha() Out[8]: 0 True 1 False 2 True Length: 3, dtype: bool In [9]: s.str.find('ab') Out[9]: 0 0 1 -1 2 -1 Length: 3, dtype: int64
Series.str.pad()
和Series.str.center()
现在接受fillchar
选项来指定填充字符 (GH 9352)In [10]: s = pd.Series(['12', '300', '25']) In [11]: s.str.pad(5, fillchar='_') Out[11]: 0 ___12 1 __300 2 ___25 Length: 3, dtype: object
添加了
Series.str.slice_replace()
,此前会引发NotImplementedError
(GH 8888)In [12]: s = pd.Series(['ABCD', 'EFGH', 'IJK']) In [13]: s.str.slice_replace(1, 3, 'X') Out[13]: 0 AXD 1 EXH 2 IX Length: 3, dtype: object # replaced with empty char In [14]: s.str.slice_replace(0, 1) Out[14]: 0 BCD 1 FGH 2 JK Length: 3, dtype: object
其他增强#
Reindex 现在支持对具有单调递增或递减索引的 DataFrame 或 Series 使用
method='nearest'
(GH 9258)In [15]: df = pd.DataFrame({'x': range(5)}) In [16]: df.reindex([0.2, 1.8, 3.5], method='nearest') Out[16]: x 0.2 0 1.8 2 3.5 4 [3 rows x 1 columns]
此方法也可通过较低级别的
Index.get_indexer
和Index.get_loc
方法使用。read_excel()
函数的 sheetname 参数现在接受列表和None
,分别用于获取多个或所有工作表。如果指定了多个工作表,则返回一个字典。(GH 9450)# Returns the 1st and 4th sheet, as a dictionary of DataFrames. pd.read_excel('path_to_file.xls', sheetname=['Sheet1', 3])
以 ~ 开头的路径现在将被扩展为以用户主目录开头 (GH 9066)
在
get_data_yahoo
中添加了时间间隔选择功能 (GH 9071)添加了
Timestamp.to_datetime64()
以补充Timedelta.to_timedelta64()
(GH 9255)tseries.frequencies.to_offset()
现在接受Timedelta
作为输入 (GH 9064)在
Series
的自相关方法中添加了 lag 参数,默认为 lag-1 自相关 (GH 9192)Timedelta
现在将在构造函数中接受nanoseconds
关键字参数 (GH 9273)SQL 代码现在能安全地转义表名和列名 (GH 8986)
添加了
Series.str.<tab>
、Series.dt.<tab>
和Series.cat.<tab>
的自动完成功能 (GH 9322)Index.get_indexer
现在即使对于任何目标数组(不仅仅是单调目标),也支持method='pad'
和method='backfill'
。这些方法也适用于单调递减和单调递增索引 (GH 9258)。Index.asof
现在适用于所有索引类型 (GH 9258)。io.read_excel()
中新增了一个verbose
参数,默认为 False。设置为 True 会在解析工作表时打印工作表名称。(GH 9450)添加了
days_in_month
(兼容性别名daysinmonth
) 属性到Timestamp
、DatetimeIndex
、Period
、PeriodIndex
和Series.dt
中 (GH 9572)在
to_csv
中添加了decimal
选项,为非 '.' 的小数点分隔符提供格式化功能 (GH 781)为
Timestamp
添加了normalize
选项,用于归一化到午夜 (GH 8794)添加了使用 HDF5 文件和
rhdf5
库将DataFrame
导入 R 的示例。更多信息请参阅文档 (GH 9636)。
向后不兼容的 API 更改#
Timedelta 的更改#
在 v0.15.0 版本中,引入了一个新的标量类型 Timedelta
,它是 datetime.timedelta
的子类。在此处提及的是关于 .seconds
访问器的 API 更改通知。其目的是提供一组用户友好的访问器,返回该单位的“自然”值,例如,如果您有一个 Timedelta('1 day, 10:11:12')
,则 .seconds
将返回 12。然而,这与 datetime.timedelta
的定义不符,后者将 .seconds
定义为 10 * 3600 + 11 * 60 + 12 == 36672
。
因此在 v0.16.0 版本中,我们将 API 恢复为与 datetime.timedelta
匹配。此外,组件值仍然可以通过 .components
访问器获取。这会影响 .seconds
和 .microseconds
访问器,并移除了 .hours
、.minutes
、.milliseconds
访问器。这些更改也影响 TimedeltaIndex
和 Series 的 .dt
访问器。(GH 9185, GH 9139)
旧行为
In [2]: t = pd.Timedelta('1 day, 10:11:12.100123')
In [3]: t.days
Out[3]: 1
In [4]: t.seconds
Out[4]: 12
In [5]: t.microseconds
Out[5]: 123
新行为
In [17]: t = pd.Timedelta('1 day, 10:11:12.100123')
In [18]: t.days
Out[18]: 1
In [19]: t.seconds
Out[19]: 36672
In [20]: t.microseconds
Out[20]: 100123
使用 .components
可以获取完整的组件访问
In [21]: t.components
Out[21]: Components(days=1, hours=10, minutes=11, seconds=12, milliseconds=100, microseconds=123, nanoseconds=0)
In [22]: t.components.seconds
Out[22]: 12
索引更改#
使用 .loc
的一小部分边缘情况的行为已发生变化 (GH 8613)。此外,我们还改进了引发的错误消息的内容
现在允许使用
.loc
进行切片时,起始和/或停止边界在索引中找不到;之前会引发KeyError
。这使得在这种情况下行为与.ix
相同。此更改仅适用于切片,不适用于使用单个标签进行索引。In [23]: df = pd.DataFrame(np.random.randn(5, 4), ....: columns=list('ABCD'), ....: index=pd.date_range('20130101', periods=5)) ....: In [24]: df Out[24]: 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-03 -0.861849 -2.104569 -0.494929 1.071804 2013-01-04 0.721555 -0.706771 -1.039575 0.271860 2013-01-05 -0.424972 0.567020 0.276232 -1.087401 [5 rows x 4 columns] In [25]: s = pd.Series(range(5), [-2, -1, 1, 2, 3]) In [26]: s Out[26]: -2 0 -1 1 1 2 2 3 3 4 Length: 5, dtype: int64
旧行为
In [4]: df.loc['2013-01-02':'2013-01-10'] KeyError: 'stop bound [2013-01-10] is not in the [index]' In [6]: s.loc[-10:3] KeyError: 'start bound [-10] is not the [index]'
新行为
In [27]: df.loc['2013-01-02':'2013-01-10'] Out[27]: A B C D 2013-01-02 1.212112 -0.173215 0.119209 -1.044236 2013-01-03 -0.861849 -2.104569 -0.494929 1.071804 2013-01-04 0.721555 -0.706771 -1.039575 0.271860 2013-01-05 -0.424972 0.567020 0.276232 -1.087401 [4 rows x 4 columns] In [28]: s.loc[-10:3] Out[28]: -2 0 -1 1 1 2 2 3 3 4 Length: 5, dtype: int64
允许在整数索引上使用浮点数类似的值对
.ix
进行切片。之前此功能仅对.loc
启用旧行为
In [8]: s.ix[-1.0:2] TypeError: the slice start value [-1.0] is not a proper indexer for this index type (Int64Index)
新行为
In [2]: s.ix[-1.0:2] Out[2]: -1 1 1 2 2 3 dtype: int64
使用
.loc
时,如果索引类型无效,则提供有用的异常信息。例如,尝试对类型为DatetimeIndex
、PeriodIndex
或TimedeltaIndex
的索引使用.loc
,并使用整数(或浮点数)进行索引。旧行为
In [4]: df.loc[2:3] KeyError: 'start bound [2] is not the [index]'
新行为
In [4]: df.loc[2:3] TypeError: Cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with <type 'int'> keys
分类类型更改#
在先前版本中,未指定排序(即未传递 ordered
关键字)的 Categoricals
默认被视为有序 Categoricals
。今后,Categorical
构造函数中的 ordered
关键字将默认为 False
。现在必须显式指定排序。
此外,之前您*可以*通过直接设置属性来更改 Categorical 的 ordered
属性,例如 cat.ordered=True
;此方法现已弃用,您应该使用 cat.as_ordered()
或 cat.as_unordered()
。这些方法默认将返回一个新对象,而不是修改现有对象。(GH 9347, GH 9190)
旧行为
In [3]: s = pd.Series([0, 1, 2], dtype='category')
In [4]: s
Out[4]:
0 0
1 1
2 2
dtype: category
Categories (3, int64): [0 < 1 < 2]
In [5]: s.cat.ordered
Out[5]: True
In [6]: s.cat.ordered = False
In [7]: s
Out[7]:
0 0
1 1
2 2
dtype: category
Categories (3, int64): [0, 1, 2]
新行为
In [29]: s = pd.Series([0, 1, 2], dtype='category')
In [30]: s
Out[30]:
0 0
1 1
2 2
Length: 3, dtype: category
Categories (3, int64): [0, 1, 2]
In [31]: s.cat.ordered
Out[31]: False
In [32]: s = s.cat.as_ordered()
In [33]: s
Out[33]:
0 0
1 1
2 2
Length: 3, dtype: category
Categories (3, int64): [0 < 1 < 2]
In [34]: s.cat.ordered
Out[34]: True
# you can set in the constructor of the Categorical
In [35]: s = pd.Series(pd.Categorical([0, 1, 2], ordered=True))
In [36]: s
Out[36]:
0 0
1 1
2 2
Length: 3, dtype: category
Categories (3, int64): [0 < 1 < 2]
In [37]: s.cat.ordered
Out[37]: True
为了方便创建分类数据 Series,我们添加了在调用 .astype()
时传递关键字参数的功能。这些参数会直接传递给构造函数。
In [54]: s = pd.Series(["a", "b", "c", "a"]).astype('category', ordered=True)
In [55]: s
Out[55]:
0 a
1 b
2 c
3 a
dtype: category
Categories (3, object): [a < b < c]
In [56]: s = (pd.Series(["a", "b", "c", "a"])
....: .astype('category', categories=list('abcdef'), ordered=False))
In [57]: s
Out[57]:
0 a
1 b
2 c
3 a
dtype: category
Categories (6, object): [a, b, c, d, e, f]
其他 API 更改#
Index.duplicated
现在返回np.array(dtype=bool)
,而不是包含bool
值的Index(dtype=object)
。(GH 8875)DataFrame.to_json
现在为混合数据类型 DataFrame 的每列返回准确的类型序列化 (GH 9037)以前数据在序列化之前被强制转换为通用数据类型,例如导致整数被序列化为浮点数
In [2]: pd.DataFrame({'i': [1,2], 'f': [3.0, 4.2]}).to_json() Out[2]: '{"f":{"0":3.0,"1":4.2},"i":{"0":1.0,"1":2.0}}'
现在每列都使用其正确的数据类型进行序列化
In [2]: pd.DataFrame({'i': [1,2], 'f': [3.0, 4.2]}).to_json() Out[2]: '{"f":{"0":3.0,"1":4.2},"i":{"0":1,"1":2}}'
DatetimeIndex
、PeriodIndex
和TimedeltaIndex.summary
现在输出相同的格式。(GH 9116)TimedeltaIndex.freqstr
现在输出与DatetimeIndex
相同的字符串格式。(GH 9116)条形图和水平条形图不再沿信息轴添加虚线。先前的样式可以通过 matplotlib 的
axhline
或axvline
方法实现 (GH 9088)。如果 Series 不包含适当类型的数据,则
Series
访问器.dt
、.cat
和.str
现在会引发AttributeError
而不是TypeError
(GH 9617)。这更紧密地遵循了 Python 的内置异常层次结构,并确保了诸如hasattr(s, 'cat')
这样的测试在 Python 2 和 3 上保持一致。Series
现在支持对整型类型进行位操作 (GH 9016)。以前即使输入数据类型是整型,输出数据类型也会被强制转换为bool
。旧行为
In [2]: pd.Series([0, 1, 2, 3], list('abcd')) | pd.Series([4, 4, 4, 4], list('abcd')) Out[2]: a True b True c True d True dtype: bool
新行为。如果输入数据类型是整型,输出数据类型也是整型,并且输出值是位操作的结果。
In [2]: pd.Series([0, 1, 2, 3], list('abcd')) | pd.Series([4, 4, 4, 4], list('abcd')) Out[2]: a 4 b 5 c 6 d 7 dtype: int64
在涉及
Series
或DataFrame
的除法运算中,0/0
和0//0
现在返回np.nan
而不是np.inf
。(GH 9144, GH 8445)旧行为
In [2]: p = pd.Series([0, 1]) In [3]: p / 0 Out[3]: 0 inf 1 inf dtype: float64 In [4]: p // 0 Out[4]: 0 inf 1 inf dtype: float64
新行为
In [38]: p = pd.Series([0, 1]) In [39]: p / 0 Out[39]: 0 NaN 1 inf Length: 2, dtype: float64 In [40]: p // 0 Out[40]: 0 NaN 1 inf Length: 2, dtype: float64
分类数据的
Series.values_counts
和Series.describe
现在将NaN
条目放在末尾。(GH 9443)分类数据的
Series.describe
现在将未使用的类别的计数和频率显示为 0,而不是NaN
(GH 9443)由于错误修复,使用
DatetimeIndex.asof
查找部分字符串标签现在会包含与字符串匹配的值,即使它们在部分字符串标签的开头之后 (GH 9258)。旧行为
In [4]: pd.to_datetime(['2000-01-31', '2000-02-28']).asof('2000-02') Out[4]: Timestamp('2000-01-31 00:00:00')
修复后的行为
In [41]: pd.to_datetime(['2000-01-31', '2000-02-28']).asof('2000-02') Out[41]: Timestamp('2000-02-28 00:00:00')
要重现旧行为,只需为标签添加更多精度(例如,使用
2000-02-01
而不是2000-02
)。
弃用#
rplot
的 Trellis 绘图接口已被弃用,并将在未来版本中移除。对于相似但更精细的功能,我们建议使用 seaborn 等外部包 (GH 3445)。文档中包含一些示例,说明如何将现有代码从rplot
转换为 seaborn,请参阅此处。pandas.sandbox.qtpandas
接口已被弃用,并将在未来版本中移除。我们建议用户使用外部包 pandas-qt。(GH 9615)将
DatetimeIndex/PeriodIndex
添加到另一个DatetimeIndex/PeriodIndex
作为集合操作已被弃用。这将在未来版本中更改为引发TypeError
。应使用.union()
进行并集集合操作。(GH 9094)将
DatetimeIndex/PeriodIndex
从另一个DatetimeIndex/PeriodIndex
中减去作为集合操作已被弃用。这将在未来版本中更改为实际的数值减法,产生一个TimeDeltaIndex
。应使用.difference()
进行差集集合操作。(GH 9094)
移除先前版本弃用/更改#
性能改进#
修复了使用数组或列表类对象进行
.loc
索引时的性能回归 (GH 9126)。DataFrame.to_json
对于混合数据类型 DataFrame 的性能提高了 30 倍。(GH 9037)性能提升:
MultiIndex.duplicated
通过使用标签而非值来工作 (GH 9125)提高了
nunique
的速度,通过调用unique
而非value_counts
(GH 9129, GH 7771)性能提升:
DataFrame.count
和DataFrame.dropna
的性能提升高达10倍,通过适当利用同质/异质数据类型 (GH 9136)性能提升:当使用
MultiIndex
和level
关键字参数时,DataFrame.count
的性能提升高达20倍 (GH 9163)性能和内存使用提升:当键空间超出
int64
范围时,merge
的性能和内存使用提升 (GH 9151)性能提升:多键
groupby
的性能提升 (GH 9429)性能提升:
MultiIndex.sortlevel
的性能提升 (GH 9445)性能和内存使用提升:
DataFrame.duplicated
的性能和内存使用提升 (GH 9398)Cython化
Period
(GH 9440)降低了
to_hdf
的内存使用 (GH 9648)
Bug 修复#
更改了
.to_html
以移除表格正文中的前后空格 (GH 4987)修复了在 Python 3 中使用
read_csv
访问 S3 时的问 (GH 9452)修复了
DatetimeIndex
中的兼容性问题,该问题影响了numpy.int_
默认设置为numpy.int32
的架构 (GH 8943)Bug 修复:Panel 索引中与类对象相关的问题 (GH 9140)
Bug 修复:返回的
Series.dt.components
索引被重置为默认索引的问题 (GH 9247)Bug 修复:
Categorical.__getitem__/__setitem__
中使用类列表输入时,索引器强制转换导致结果不正确的问题 (GH 9469)Bug 修复:使用 DatetimeIndex 进行部分设置的问题 (GH 9478)
Bug 修复:在分组操作中,对整数和 datetime64 列应用聚合器时,当数值足够大时导致值发生改变的问题 (GH 9311, GH 6620)
修复了将
Timestamp
对象列(带有时区信息的 datetime 列)映射到相应的 sqlalchemy 类型时to_sql
中的错误 (GH 9085)。修复了
to_sql
的dtype
参数不接受实例化 SQLAlchemy 类型的问题 (GH 9083)。Bug 修复:使用
np.datetime64
进行.loc
部分设置的问题 (GH 9516)对看起来像 datetimelike 的
Series
和.xs
切片推断的数据类型不正确 (GH 9477)Categorical.unique()
中的项(如果s
的 dtype 是category
,则s.unique()
中的项)现在按照其原始找到的顺序出现,而非按排序顺序 (GH 9331)。这现在与 pandas 中其他数据类型的行为一致。修复了在大端序平台上
StataReader
产生错误结果的 bug (GH 8688)。Bug 修复:
MultiIndex.has_duplicates
中层级过多导致索引器溢出的问题 (GH 9075, GH 5873)Bug 修复:
pivot
和unstack
中,nan
值破坏索引对齐的问题 (GH 4862, GH 7401, GH 7403, GH 7405, GH 7466, GH 9497)Bug 修复:对带有
sort=True
或空值的 MultiIndex 进行左连接的问题 (GH 9210)。Bug 修复:
MultiIndex
中插入新键失败的问题 (GH 9250)。Bug 修复:分组操作中,当键空间超出
int64
范围时的问题 (GH 9096)。Bug 修复:对带有
TimedeltaIndex
或DatetimeIndex
及空值的unstack
操作的问题 (GH 9491)。Bug 修复:
rank
中,带容差比较浮点数会导致不一致行为的问题 (GH 8365)。修复了从 URL 加载数据时
read_stata
和StataReader
中的字符编码 bug (GH 9231)。Bug 修复:将
offsets.Nano
添加到其他 offset 会引发TypeError
的问题 (GH 9284)Bug 修复:
DatetimeIndex
迭代中的 bug,与 (GH 8890) 相关,在 (GH 9100) 中修复Bug 修复:
resample
在夏令时转换附近的 bug。这需要修复 offset 类以使其在夏令时转换时行为正确。 (GH 5172, GH 8744, GH 8653, GH 9173, GH 9468)。Bug 修复:二元运算符方法(例如
.mul()
)与整数级别对齐的问题 (GH 9463)。Bug 修复:箱线图、散点图和六边形图可能显示不必要的警告 (GH 8877)
Bug 修复:使用
layout
关键字的子图可能显示不必要的警告 (GH 9464)Bug 修复:使用需要传递参数(例如 axis)的分组器函数时,使用包装函数(例如
fillna
)的问题 (GH 9221)DataFrame
现在正确支持在构造函数中同时使用copy
和dtype
参数 (GH 9099)Bug 修复:使用 C 引擎在具有 CR 行结束符的文件上使用 skiprows 读取
read_csv
文件的问题。 (GH 9079)isnull
现在可以检测PeriodIndex
中的NaT
(GH 9129)Bug 修复:多列分组时 groupby
.nth()
中的 bug (GH 8979)Bug 修复:
DataFrame.where
和Series.where
将数值强制转换为字符串时出错 (GH 9280)Bug 修复:
DataFrame.where
和Series.where
在传递类字符串列表时引发ValueError
的问题。 (GH 9280)对非字符串值访问
Series.str
方法现在会引发TypeError
,而不是产生错误结果 (GH 9184)Bug 修复:
DatetimeIndex.__contains__
在索引包含重复值且不是单调递增时的问题 (GH 9512)修复了当所有值都相等时
Series.kurt()
的除零错误 (GH 9197)修复了
xlsxwriter
引擎中的问题,该问题在未应用其他格式时向单元格添加默认的“常规”格式。这阻止了其他行或列格式的应用。 (GH 9167)修复了在
read_csv
中同时指定index_col=False
和usecols
时的 (GH 9082)Bug 修复:
wide_to_long
会修改输入的 stub 名称列表的问题 (GH 9204)Bug 修复:
to_sql
未使用双精度存储 float64 值的问题。 (GH 9009)SparseSeries
和SparsePanel
现在接受零参数构造函数(与其非稀疏对应项相同) (GH 9272)。合并
Categorical
和object
数据类型时的回归问题 (GH 9426)Bug 修复:
read_csv
在处理某些格式错误输入文件时发生缓冲区溢出的问题 (GH 9205)修复了
Series.groupby
中,按 MultiIndex 级别分组时会忽略 sort 参数的 bug (GH 9444)修复了
DataFrame.Groupby
中,在 Categorical 列的情况下sort=False
被忽略的 bug。 (GH 8868)修复了在 Python 3 中从 Amazon S3 读取 CSV 文件时引发 TypeError 的 bug (GH 9452)
Bug 修复:Google BigQuery 读取器中,查询结果可能包含 ‘jobComplete’ 键但其值为 False 的问题 (GH 8728)
Bug 修复:
Series.values_counts
中,对于dropna=True
的分类类型Series
,排除NaN
值的问题 (GH 9443)修复了
DataFrame.std/var/sem
缺少 numeric_only 选项的问题 (GH 9201)支持使用标量数据构造
Panel
或Panel4D
(GH 8285)Series
文本表示与max_rows
/max_columns
断开 (GH 7508)。
Series
截断时数字格式不一致 (GH 8532)。旧行为
In [2]: pd.options.display.max_rows = 10 In [3]: s = pd.Series([1,1,1,1,1,1,1,1,1,1,0.9999,1,1]*10) In [4]: s Out[4]: 0 1 1 1 2 1 ... 127 0.9999 128 1.0000 129 1.0000 Length: 130, dtype: float64
新行为
0 1.0000 1 1.0000 2 1.0000 3 1.0000 4 1.0000 ... 125 1.0000 126 1.0000 127 0.9999 128 1.0000 129 1.0000 dtype: float64
在某些情况下,在帧中设置新项时会生成一个虚假的
SettingWithCopy
警告 (GH 8730)以下操作之前会报告一个
SettingWithCopy
警告。In [42]: df1 = pd.DataFrame({'x': pd.Series(['a', 'b', 'c']), ....: 'y': pd.Series(['d', 'e', 'f'])}) ....: In [43]: df2 = df1[['x']] In [44]: df2['y'] = ['g', 'h', 'i']
贡献者#
本次发布共有 60 位贡献者提交了补丁。名字旁带有“+”的人员是首次贡献补丁。
Aaron Toth +
Alan Du +
Alessandro Amici +
Artemy Kolchinsky
Ashwini Chaudhary +
Ben Schiller
Bill Letson
Brandon Bradley +
Chau Hoang +
Chris Reynolds
Chris Whelan +
Christer van der Meeren +
David Cottrell +
David Stephens
Ehsan Azarnasab +
Garrett-R +
Guillaume Gay
Jake Torcasso +
Jason Sexauer
Jeff Reback
John McNamara
Joris Van den Bossche
Joschka zur Jacobsmühlen +
Juarez Bochi +
Junya Hayashi +
K.-Michael Aye
Kerby Shedden +
Kevin Sheppard
Kieran O’Mahony
Kodi Arfer +
Matti Airas +
Min RK +
Mortada Mehyar
Robert +
Scott E Lasley
Scott Lasley +
Sergio Pascual +
Skipper Seabold
Stephan Hoyer
Thomas Grainger
Tom Augspurger
TomAugspurger
Vladimir Filimonov +
Vyomkesh Tripathi +
Will Holmgren
Yulong Yang +
behzad nouri
bertrandhaut +
bjonen
cel4 +
clham
hsperr +
ischwabacher
jnmclarty
josham +
jreback
omtinez +
roch +
sinhrks
unutbu