版本 0.18.1 (2016年5月3日)#
这是 0.18.0 的一个次要错误修复版本,包含了大量错误修复以及几项新功能、增强功能和性能改进。我们建议所有用户升级到此版本。
亮点包括
.groupby(...)
已得到增强,以便在使用.rolling(..)
、.expanding(..)
和.resample(..)
进行分组时提供便捷的语法,详见 此处pd.to_datetime()
已获得从DataFrame
组装日期的能力,详见 此处方法链改进,详见 此处。
自定义营业时间偏移,详见 此处。
sparse
处理中的许多错误修复,详见 此处扩展了 教程部分,其中包含一篇关于现代 pandas 的专题,由 @TomAugsburger 提供。(GH 13045)。
v0.18.1 新功能
新功能#
自定义营业时间#
CustomBusinessHour
是 BusinessHour
和 CustomBusinessDay
的混合,允许您指定任意假期。详情请参阅 自定义营业时间 (GH 11514)
In [1]: from pandas.tseries.offsets import CustomBusinessHour
In [2]: from pandas.tseries.holiday import USFederalHolidayCalendar
In [3]: bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())
马丁·路德·金纪念日前的星期五
In [4]: import datetime
In [5]: dt = datetime.datetime(2014, 1, 17, 15)
In [6]: dt + bhour_us
Out[6]: Timestamp('2014-01-17 16:00:00')
马丁·路德·金纪念日后的星期二 (星期一因是假期而跳过)
In [7]: dt + bhour_us * 2
Out[7]: Timestamp('2014-01-20 09:00:00')
使用窗口和重采样操作的 .groupby(..)
方法语法#
.groupby(...)
已得到增强,以便在使用 .rolling(..)
、.expanding(..)
和 .resample(..)
进行分组时提供便捷的语法,详见 (GH 12486, GH 12738)。
您现在可以将 .rolling(..)
和 .expanding(..)
作为 groupby 的方法使用。这些方法会返回另一个延迟对象 (类似于 .rolling()
和 .expanding()
在未分组的 pandas 对象上所做的操作)。然后,您可以以类似的方式操作这些 RollingGroupby
对象。
以前,您必须这样做才能获取每组的滚动窗口平均值
In [8]: df = pd.DataFrame({"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)})
In [9]: df
Out[9]:
A B
0 1 0
1 1 1
2 1 2
3 1 3
4 1 4
.. .. ..
35 3 35
36 3 36
37 3 37
38 3 38
39 3 39
[40 rows x 2 columns]
In [1]: df.groupby("A").apply(lambda x: x.rolling(4).B.mean())
Out[1]:
A
1 0 NaN
1 NaN
2 NaN
3 1.5
4 2.5
5 3.5
6 4.5
7 5.5
8 6.5
9 7.5
10 8.5
11 9.5
12 10.5
13 11.5
14 12.5
15 13.5
16 14.5
17 15.5
18 16.5
19 17.5
2 20 NaN
21 NaN
22 NaN
23 21.5
24 22.5
25 23.5
26 24.5
27 25.5
28 26.5
29 27.5
30 28.5
31 29.5
3 32 NaN
33 NaN
34 NaN
35 33.5
36 34.5
37 35.5
38 36.5
39 37.5
Name: B, dtype: float64
现在您可以这样做
In [10]: df.groupby("A").rolling(4).B.mean()
Out[10]:
A
1 0 NaN
1 NaN
2 NaN
3 1.5
4 2.5
...
3 35 33.5
36 34.5
37 35.5
38 36.5
39 37.5
Name: B, Length: 40, dtype: float64
对于 .resample(..)
类型的操作,以前您必须
In [11]: df = pd.DataFrame(
....: {
....: "date": pd.date_range(start="2016-01-01", periods=4, freq="W"),
....: "group": [1, 1, 2, 2],
....: "val": [5, 6, 7, 8],
....: }
....: ).set_index("date")
....:
In [12]: df
Out[12]:
group val
date
2016-01-03 1 5
2016-01-10 1 6
2016-01-17 2 7
2016-01-24 2 8
[4 rows x 2 columns]
In[1]: df.groupby("group").apply(lambda x: x.resample("1D").ffill())
Out[1]:
group val
group date
1 2016-01-03 1 5
2016-01-04 1 5
2016-01-05 1 5
2016-01-06 1 5
2016-01-07 1 5
2016-01-08 1 5
2016-01-09 1 5
2016-01-10 1 6
2 2016-01-17 2 7
2016-01-18 2 7
2016-01-19 2 7
2016-01-20 2 7
2016-01-21 2 7
2016-01-22 2 7
2016-01-23 2 7
2016-01-24 2 8
现在您可以这样做
In[1]: df.groupby("group").resample("1D").ffill()
Out[1]:
group val
group date
1 2016-01-03 1 5
2016-01-04 1 5
2016-01-05 1 5
2016-01-06 1 5
2016-01-07 1 5
2016-01-08 1 5
2016-01-09 1 5
2016-01-10 1 6
2 2016-01-17 2 7
2016-01-18 2 7
2016-01-19 2 7
2016-01-20 2 7
2016-01-21 2 7
2016-01-22 2 7
2016-01-23 2 7
2016-01-24 2 8
方法链改进#
以下方法/索引器现在接受 callable
。它旨在使这些方法在方法链中更有用,请参阅文档。(GH 11485, GH 12533)
.where()
和.mask()
.loc[]
、iloc[]
和.ix[]
[]
索引
方法 .where()
和 .mask()
#
这些可以接受条件和 other
参数的可调用对象。
In [13]: df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
In [14]: df.where(lambda x: x > 4, lambda x: x + 10)
Out[14]:
A B C
0 11 14 7
1 12 5 8
2 13 6 9
[3 rows x 3 columns]
方法 .loc[]
、.iloc[]
、.ix[]
#
这些可以接受可调用对象和作为切片器的可调用对象元组。可调用对象可以返回一个有效的布尔索引器或任何对这些索引器输入有效的内容。
# callable returns bool indexer
In [15]: df.loc[lambda x: x.A >= 2, lambda x: x.sum() > 10]
Out[15]:
B C
1 5 8
2 6 9
[2 rows x 2 columns]
# callable returns list of labels
In [16]: df.loc[lambda x: [1, 2], lambda x: ["A", "B"]]
Out[16]:
A B
1 2 5
2 3 6
[2 rows x 2 columns]
使用 []
索引#
最后,您可以在 Series、DataFrame 和 Panel 的 []
索引中使用可调用对象。可调用对象必须根据其类和索引类型返回 []
索引的有效输入。
In [17]: df[lambda x: "A"]
Out[17]:
0 1
1 2
2 3
Name: A, Length: 3, dtype: int64
使用这些方法/索引器,您可以链式数据选择操作,而无需使用临时变量。
In [18]: bb = pd.read_csv("data/baseball.csv", index_col="id")
In [19]: (bb.groupby(["year", "team"]).sum(numeric_only=True).loc[lambda df: df.r > 100])
Out[19]:
stint g ab r h X2b ... so ibb hbp sh sf gidp
year team ...
2007 CIN 6 379 745 101 203 35 ... 127.0 14.0 1.0 1.0 15.0 18.0
DET 5 301 1062 162 283 54 ... 176.0 3.0 10.0 4.0 8.0 28.0
HOU 4 311 926 109 218 47 ... 212.0 3.0 9.0 16.0 6.0 17.0
LAN 11 413 1021 153 293 61 ... 141.0 8.0 9.0 3.0 8.0 29.0
NYN 13 622 1854 240 509 101 ... 310.0 24.0 23.0 18.0 15.0 48.0
SFN 5 482 1305 198 337 67 ... 188.0 51.0 8.0 16.0 6.0 41.0
TEX 2 198 729 115 200 40 ... 140.0 4.0 5.0 2.0 8.0 16.0
TOR 4 459 1408 187 378 96 ... 265.0 16.0 12.0 4.0 16.0 38.0
[8 rows x 18 columns]
DatetimeIndex
作为 MultiIndex
一部分时的部分字符串索引#
当 DateTimeIndex
是 MultiIndex
的一部分时,部分字符串索引现在可以匹配 (GH 10331)
In [20]: dft2 = pd.DataFrame(
....: np.random.randn(20, 1),
....: columns=["A"],
....: index=pd.MultiIndex.from_product(
....: [pd.date_range("20130101", periods=10, freq="12H"), ["a", "b"]]
....: ),
....: )
....:
In [21]: dft2
Out[21]:
A
2013-01-01 00:00:00 a 0.469112
b -0.282863
2013-01-01 12:00:00 a -1.509059
b -1.135632
2013-01-02 00:00:00 a 1.212112
... ...
2013-01-04 12:00:00 b 0.271860
2013-01-05 00:00:00 a -0.424972
b 0.567020
2013-01-05 12:00:00 a 0.276232
b -1.087401
[20 rows x 1 columns]
In [22]: dft2.loc["2013-01-05"]
Out[22]:
A
2013-01-05 00:00:00 a -0.424972
b 0.567020
2013-01-05 12:00:00 a 0.276232
b -1.087401
[4 rows x 1 columns]
在其他级别上
In [26]: idx = pd.IndexSlice
In [27]: dft2 = dft2.swaplevel(0, 1).sort_index()
In [28]: dft2
Out[28]:
A
a 2013-01-01 00:00:00 0.469112
2013-01-01 12:00:00 -1.509059
2013-01-02 00:00:00 1.212112
2013-01-02 12:00:00 0.119209
2013-01-03 00:00:00 -0.861849
... ...
b 2013-01-03 12:00:00 1.071804
2013-01-04 00:00:00 -0.706771
2013-01-04 12:00:00 0.271860
2013-01-05 00:00:00 0.567020
2013-01-05 12:00:00 -1.087401
[20 rows x 1 columns]
In [29]: dft2.loc[idx[:, "2013-01-05"], :]
Out[29]:
A
a 2013-01-05 00:00:00 -0.424972
2013-01-05 12:00:00 0.276232
b 2013-01-05 00:00:00 0.567020
2013-01-05 12:00:00 -1.087401
[4 rows x 1 columns]
组装日期时间#
pd.to_datetime()
已获得了从传入的 DataFrame
或字典中组装日期时间的能力。(GH 8158)。
In [20]: df = pd.DataFrame(
....: {"year": [2015, 2016], "month": [2, 3], "day": [4, 5], "hour": [2, 3]}
....: )
....:
In [21]: df
Out[21]:
year month day hour
0 2015 2 4 2
1 2016 3 5 3
[2 rows x 4 columns]
使用传入的 frame 进行组装。
In [22]: pd.to_datetime(df)
Out[22]:
0 2015-02-04 02:00:00
1 2016-03-05 03:00:00
Length: 2, dtype: datetime64[ns]
您只能传递需要组装的列。
In [23]: pd.to_datetime(df[["year", "month", "day"]])
Out[23]:
0 2015-02-04
1 2016-03-05
Length: 2, dtype: datetime64[ns]
其他增强功能#
pd.read_csv()
现在支持 Python 引擎的delim_whitespace=True
(GH 12958)pd.read_csv()
现在支持通过扩展名推断或显式compression='zip'
打开包含单个 CSV 的 ZIP 文件 (GH 12175)pd.read_csv()
现在支持通过扩展名推断或显式指定compression='xz'
来打开使用 xz 压缩的文件;xz
压缩也以相同的方式受到DataFrame.to_csv
的支持 (GH 11852)pd.read_msgpack()
现在即使在使用压缩时也始终提供可写入的 ndarray (GH 12359)。pd.read_msgpack()
现在支持使用 msgpack 序列化和反序列化分类数据 (GH 12573).to_json()
现在支持包含分类和稀疏数据的NDFrames
(GH 10778)interpolate()
现在支持method='akima'
(GH 7588)。pd.read_excel()
现在接受用于文件路径的路径对象(例如pathlib.Path
,py.path.local
),与其他read_*
函数一致 (GH 12655)添加了
.weekday_name
属性作为DatetimeIndex
和.dt
访问器的一个组件。(GH 11128)Index.take
现在一致地处理allow_fill
和fill_value
(GH 12631)In [24]: idx = pd.Index([1.0, 2.0, 3.0, 4.0], dtype="float") # default, allow_fill=True, fill_value=None In [25]: idx.take([2, -1]) Out[25]: Index([3.0, 4.0], dtype='float64') In [26]: idx.take([2, -1], fill_value=True) Out[26]: Index([3.0, nan], dtype='float64')
Index
现在支持.str.get_dummies()
,它返回MultiIndex
,详见 创建指示变量 (GH 10008, GH 10103)In [27]: idx = pd.Index(["a|b", "a|c", "b|c"]) In [28]: idx.str.get_dummies("|") Out[28]: MultiIndex([(1, 1, 0), (1, 0, 1), (0, 1, 1)], names=['a', 'b', 'c'])
pd.crosstab()
增加了normalize
参数,用于规范化频率表 (GH 12569)。更新文档中的示例此处。现在支持
.resample(..).interpolate()
(GH 12925).isin()
现在接受传入的sets
(GH 12988)
稀疏数据更改#
这些更改使稀疏数据处理符合返回正确的类型并使索引操作更顺畅。
SparseArray.take
现在对于标量输入返回一个标量,对于其他情况返回 SparseArray
。此外,它以与 Index
相同的规则处理负索引器 (GH 10560, GH 12796)
s = pd.SparseArray([np.nan, np.nan, 1, 2, 3, np.nan, 4, 5, np.nan, 6])
s.take(0)
s.take([1, 2, 3])
SparseSeries[]
使用Ellipsis
索引时引发KeyError
的错误 (GH 9467)SparseArray[]
使用元组索引时未正确处理的错误 (GH 12966)SparseSeries.loc[]
使用列表式输入时引发TypeError
的错误 (GH 10560)SparseSeries.iloc[]
使用标量输入时可能引发IndexError
的错误 (GH 10560)SparseSeries.loc[]
,.iloc[]
使用slice
返回SparseArray
而不是SparseSeries
的错误 (GH 10560)SparseDataFrame.loc[]
,.iloc[]
可能导致稠密Series
而不是SparseSeries
的错误 (GH 12787)SparseArray
加法忽略右侧fill_value
的错误 (GH 12910)SparseArray
mod 操作引发AttributeError
的错误 (GH 12910)SparseArray
pow 计算1 ** np.nan
为np.nan
,而它必须是 1 的错误 (GH 12910)SparseArray
比较输出可能结果不正确或引发ValueError
的错误 (GH 12971)SparseSeries.__repr__
在长度超过max_rows
时引发TypeError
的错误 (GH 10560)SparseSeries.shape
忽略fill_value
的错误 (GH 10452)SparseSeries
和SparseArray
可能与其稠密值具有不同dtype
的错误 (GH 12908)SparseSeries.reindex
未正确处理fill_value
的错误 (GH 12797)SparseArray.to_frame()
结果为DataFrame
而不是SparseDataFrame
的错误 (GH 9850)SparseSeries.value_counts()
未计数fill_value
的错误 (GH 6749)SparseArray.to_dense()
未保留dtype
的错误 (GH 10648)SparseArray.to_dense()
未正确处理fill_value
的错误 (GH 12797)pd.concat()
稀疏序列结果为稠密的错误 (GH 10536)pd.concat()
稀疏数据框未正确处理fill_value
的错误 (GH 9765)pd.concat()
稀疏数据框可能引发AttributeError
的错误 (GH 12174)SparseArray.shift()
可能引发NameError
或TypeError
的错误 (GH 12908)
API 更改#
方法 .groupby(..).nth()
更改#
当传递 as_index
参数时,.groupby(..).nth()
输出中的索引现在更加一致 (GH 11039)
In [29]: df = pd.DataFrame({"A": ["a", "b", "a"], "B": [1, 2, 3]})
In [30]: df
Out[30]:
A B
0 a 1
1 b 2
2 a 3
[3 rows x 2 columns]
先前行为
In [3]: df.groupby('A', as_index=True)['B'].nth(0)
Out[3]:
0 1
1 2
Name: B, dtype: int64
In [4]: df.groupby('A', as_index=False)['B'].nth(0)
Out[4]:
0 1
1 2
Name: B, dtype: int64
新行为
In [31]: df.groupby("A", as_index=True)["B"].nth(0)
Out[31]:
0 1
1 2
Name: B, Length: 2, dtype: int64
In [32]: df.groupby("A", as_index=False)["B"].nth(0)
Out[32]:
0 1
1 2
Name: B, Length: 2, dtype: int64
此外,以前,.groupby
总是会排序,无论是否传入 sort=False
与 .nth()
一起。
In [33]: np.random.seed(1234)
In [34]: df = pd.DataFrame(np.random.randn(100, 2), columns=["a", "b"])
In [35]: df["c"] = np.random.randint(0, 4, 100)
先前行为
In [4]: df.groupby('c', sort=True).nth(1)
Out[4]:
a b
c
0 -0.334077 0.002118
1 0.036142 -2.074978
2 -0.720589 0.887163
3 0.859588 -0.636524
In [5]: df.groupby('c', sort=False).nth(1)
Out[5]:
a b
c
0 -0.334077 0.002118
1 0.036142 -2.074978
2 -0.720589 0.887163
3 0.859588 -0.636524
新行为
In [36]: df.groupby("c", sort=True).nth(1)
Out[36]:
a b c
2 -0.720589 0.887163 2
3 0.859588 -0.636524 3
7 -0.334077 0.002118 0
21 0.036142 -2.074978 1
[4 rows x 3 columns]
In [37]: df.groupby("c", sort=False).nth(1)
Out[37]:
a b c
2 -0.720589 0.887163 2
3 0.859588 -0.636524 3
7 -0.334077 0.002118 0
21 0.036142 -2.074978 1
[4 rows x 3 columns]
NumPy 函数兼容性#
通过增加 pandas
方法的签名,使其能够接受从 numpy
传入的参数,即使它们不一定在 pandas
实现中使用,极大地提高了 pandas 数组式方法(例如 sum
和 take
)与其 numpy
对应方法之间的兼容性 (GH 12644, GH 12638, GH 12687)
Index
和TimedeltaIndex
的.searchsorted()
现在接受sorter
参数,以保持与 numpy 的searchsorted
函数的兼容性 (GH 12238)np.round()
在Series
上的 numpy 兼容性错误 (GH 12600)
下面演示了此签名增强的一个示例
sp = pd.SparseDataFrame([1, 2, 3])
sp
先前行为
In [2]: np.cumsum(sp, axis=0)
...
TypeError: cumsum() takes at most 2 arguments (4 given)
新行为
np.cumsum(sp, axis=0)
在 GroupBy 重采样上使用 .apply
#
在重采样 groupby 操作(使用 pd.TimeGrouper
)上使用 apply
现在具有与在其他 groupby 操作上类似的 apply
调用相同的输出类型。(GH 11742)。
In [38]: df = pd.DataFrame(
....: {"date": pd.to_datetime(["10/10/2000", "11/10/2000"]), "value": [10, 13]}
....: )
....:
In [39]: df
Out[39]:
date value
0 2000-10-10 10
1 2000-11-10 13
[2 rows x 2 columns]
先前行为
In [1]: df.groupby(pd.TimeGrouper(key='date',
...: freq='M')).apply(lambda x: x.value.sum())
Out[1]:
...
TypeError: cannot concatenate a non-NDFrame object
# Output is a Series
In [2]: df.groupby(pd.TimeGrouper(key='date',
...: freq='M')).apply(lambda x: x[['value']].sum())
Out[2]:
date
2000-10-31 value 10
2000-11-30 value 13
dtype: int64
新行为
# Output is a Series
In [55]: df.groupby(pd.TimeGrouper(key='date',
...: freq='M')).apply(lambda x: x.value.sum())
Out[55]:
date
2000-10-31 10
2000-11-30 13
Freq: M, dtype: int64
# Output is a DataFrame
In [56]: df.groupby(pd.TimeGrouper(key='date',
...: freq='M')).apply(lambda x: x[['value']].sum())
Out[56]:
value
date
2000-10-31 10
2000-11-30 13
read_csv
异常更改#
为了标准化 read_csv
的 API,对于 c
和 python
引擎,现在都将对空列或空头文件引发 EmptyDataError
(ValueError
的子类)(GH 12493, GH 12506)
先前行为
In [1]: import io
In [2]: df = pd.read_csv(io.StringIO(''), engine='c')
...
ValueError: No columns to parse from file
In [3]: df = pd.read_csv(io.StringIO(''), engine='python')
...
StopIteration
新行为
In [1]: df = pd.read_csv(io.StringIO(''), engine='c')
...
pandas.io.common.EmptyDataError: No columns to parse from file
In [2]: df = pd.read_csv(io.StringIO(''), engine='python')
...
pandas.io.common.EmptyDataError: No columns to parse from file
除了这个错误更改外,还进行了其他几项更改
CParserError
现在是ValueError
的子类,而不仅仅是Exception
(GH 12551)当
c
引擎无法解析列时,read_csv
现在将引发CParserError
而不是通用的Exception
(GH 12506)当
c
引擎在整数列中遇到NaN
值时,read_csv
现在将引发ValueError
而不是通用的Exception
(GH 12506)当指定了
true_values
并且c
引擎在包含不可编码字节的列中遇到元素时,read_csv
现在将引发ValueError
而不是通用的Exception
(GH 12506)pandas.parser.OverflowError
异常已被移除,并已被 Python 内置的OverflowError
异常替换 (GH 12506)pd.read_csv()
不再允许usecols
参数同时包含字符串和整数 (GH 12678)
方法 to_datetime
错误更改#
pd.to_datetime()
在传递带有可转换条目且 errors='coerce'
,或带有不可转换条目且 errors='ignore'
的 unit
时出现错误。此外,当遇到超出该单位范围的值时,如果 errors='raise'
,则会引发 OutOfBoundsDateime
异常。(GH 11758, GH 13052, GH 13059)
先前行为
In [27]: pd.to_datetime(1420043460, unit='s', errors='coerce')
Out[27]: NaT
In [28]: pd.to_datetime(11111111, unit='D', errors='ignore')
OverflowError: Python int too large to convert to C long
In [29]: pd.to_datetime(11111111, unit='D', errors='raise')
OverflowError: Python int too large to convert to C long
新行为
In [2]: pd.to_datetime(1420043460, unit='s', errors='coerce')
Out[2]: Timestamp('2014-12-31 16:31:00')
In [3]: pd.to_datetime(11111111, unit='D', errors='ignore')
Out[3]: 11111111
In [4]: pd.to_datetime(11111111, unit='D', errors='raise')
OutOfBoundsDatetime: cannot convert input with unit 'D'
其他 API 更改#
Series
、DataFrame
、Panel
和MultiIndex
的.swaplevel()
现在对其前两个参数i
和j
设置了默认值,它们会交换索引的最内层两个级别。(GH 12934)Index
和TimedeltaIndex
的.searchsorted()
现在接受sorter
参数,以保持与 numpy 的searchsorted
函数的兼容性 (GH 12238)Period
和PeriodIndex
现在引发继承自ValueError
的IncompatibleFrequency
错误,而不是原始ValueError
(GH 12615)类别 dtype 的
Series.apply
现在将传入的函数应用于每个.categories
(而不是.codes
),并尽可能返回category
dtype (GH 12473)如果
parse_dates
既不是布尔值、列表也不是字典(与 doc-string 匹配),read_csv
现在将引发TypeError
(GH 5636).query()/.eval()
的默认值现在是engine=None
,如果安装了numexpr
,它将使用numexpr
;否则将回退到python
引擎。这模仿了 0.18.1 版本之前的行为,如果安装了numexpr
(并且之前,如果未安装 numexpr,.query()/.eval()
将引发错误)。(GH 12749)pd.show_versions()
现在包含pandas_datareader
版本 (GH 12740)为通用函数提供适当的
__name__
和__qualname__
属性 (GH 12021)pd.concat(ignore_index=True)
现在默认使用RangeIndex
(GH 12695)pd.merge()
和DataFrame.join()
在合并/连接单层和多层数据框时将显示UserWarning
(GH 9455, GH 12219)与
scipy
> 0.17 的兼容性,适用于已弃用的piecewise_polynomial
插值方法;支持替换的from_derivatives
方法 (GH 12887)
弃用#
性能改进#
.groupby(..).cumcount()
性能改进 (GH 11039)使用
skiprows=an_integer
时,pd.read_csv()
的内存使用量得到改进 (GH 13005)DataFrame.to_sql
在检查表名大小写敏感性时的性能得到改进。现在只在表名不是小写时才检查表是否已正确创建。(GH 12876).str.encode()
和.str.decode()
方法的性能得到改进 (GH 13008)如果输入是数字 dtype,
to_numeric
的性能得到改进 (GH 12777)使用
IntIndex
进行稀疏运算的性能得到改进 (GH 13036)
错误修复#
pd.read_csv
中的usecols
参数现在即使 CSV 文件行不均匀也能被遵守 (GH 12203)当使用非单调有序索引指定
axis=1
时,groupby.transform(..)
的错误 (GH 12713)当指定
freq="Minute"
时,Period
和PeriodIndex
创建引发KeyError
的错误。请注意,“Minute”频率在 v0.17.0 中已弃用,建议使用freq="T"
代替 (GH 11854)带有
PeriodIndex
的.resample(...).count()
总是引发TypeError
的错误 (GH 12774)当为空时,带有
PeriodIndex
的.resample(...)
转换为DatetimeIndex
的错误 (GH 12868)当重采样到现有频率时,带有
PeriodIndex
的.resample(...)
的错误 (GH 12770)打印包含不同
freq
的Period
数据时引发ValueError
的错误 (GH 12615)当指定
Categorical
和dtype='category'
时,Series
构造的错误 (GH 12574)当可强制转换的 dtype 的连接过于激进,导致当对象长度超过
display.max_rows
时,输出格式中的 dtype 不同步的错误 (GH 12411, GH 12045, GH 11594, GH 10571, GH 12211)float_format
选项未验证为可调用对象的错误。(GH 12706)当
dropna=False
且没有组满足条件时,GroupBy.filter
的错误 (GH 12768).cum*
函数的__name__
错误 (GH 12021)Float64Inde/Int64Index
转换为Int64Index
时,.astype()
的错误 (GH 12881)当
orient='index'
(默认)时,.to_json()/.read_json()
中整数索引往返的错误 (GH 12866)绘制
Categorical
数据类型时,尝试堆叠条形图导致错误的错误 (GH 13019)与 >=
numpy
1.11 的NaT
比较的兼容性 (GH 12969)使用非唯一
MultiIndex
的.drop()
中的错误。(GH 12701)时区感知和非时区感知数据框的
.concat
中的错误 (GH 12467)在
.resample(..).fillna(..)
中传递非字符串时未能正确引发ValueError
的错误 (GH 12952)pd.read_sas()
中各种编码和头部处理问题的错误修复 (GH 12659, GH 12654, GH 12647, GH 12809)当
values=None
时,pd.crosstab()
会静默忽略aggfunc
的错误 (GH 12569)。DataFrame.to_json
序列化datetime.time
时可能发生的段错误 (GH 11473)。DataFrame.to_json
尝试序列化 0d 数组时可能出现的段错误 (GH 11299)。当尝试序列化带有非 ndarray 值的
DataFrame
或Series
时,to_json
中的段错误;现在支持category
、sparse
和datetime64[ns, tz]
dtypes 的序列化 (GH 10778)。DataFrame.to_json
中未支持的 dtype 未传递给默认处理程序的错误 (GH 12554)。.align
未返回子类的错误 (GH 12983)Series
与DataFrame
对齐时的错误 (GH 13037)ABCPanel
中的错误,其中Panel4D
未被视为此通用类型的有效实例 (GH 12810).groupby(..).apply(..)
情况中.name
一致性错误 (GH 12363)Timestamp.__repr__
中的错误,导致pprint
在嵌套结构中失败 (GH 12622)Timedelta.min
和Timedelta.max
的错误,现在这些属性报告 pandas 识别的真正最小/最大timedeltas
。请参阅文档。(GH 12727).quantile()
带有插值时可能意外强制转换为float
的错误 (GH 12772).quantile()
带有空Series
时可能返回标量而不是空Series
的错误 (GH 12772).loc
在大索引器中越界时会引发IndexError
而不是KeyError
的错误 (GH 12527)在使用
TimedeltaIndex
和.asfreq()
进行重采样时,以前不会包含最终的栅栏柱的错误 (GH 12926)DataFrame
中Categorical
的相等性测试错误 (GH 12564)当使用
TimeGrouper
时,GroupBy.first()
和.last()
返回不正确行的错误 (GH 7453)当使用
c
引擎且在引用项中包含换行符时,pd.read_csv()
中指定skiprows
的错误 (GH 10911, GH 12775)当分配时区感知日期时间
Series
并进行对齐时,DataFrame
时区丢失的错误 (GH 12981)当
normalize=True
和dropna=True
时,.value_counts()
中的错误,其中空值仍然计入标准化计数 (GH 12558)如果
Series.value_counts()
的 dtype 是category
,则丢失名称的错误 (GH 12835)Series.value_counts()
丢失时区信息的错误 (GH 12835)当
normalize=True
且带有Categorical
时,Series.value_counts()
引发UnboundLocalError
的错误 (GH 12835)Panel.fillna()
忽略inplace=True
的错误 (GH 12633)当同时使用
c
引擎指定names
、usecols
和parse_dates
时,pd.read_csv()
的错误 (GH 9755)当使用
c
引擎同时指定delim_whitespace=True
和lineterminator
时,pd.read_csv()
的错误 (GH 12912)Series.rename
、DataFrame.rename
和DataFrame.rename_axis
未将Series
视为重新标记的映射的错误 (GH 12623)。.rolling.min
和.rolling.max
的清理以增强 dtype 处理 (GH 12373)groupby 中复杂类型被强制转换为 float 的错误 (GH 12902)
如果
Series.map
的 dtype 是category
或时区感知datetime
,则引发TypeError
的错误 (GH 12473)32 位平台上某些测试比较的错误 (GH 12972)
从
RangeIndex
构造回退时,索引强制转换的错误 (GH 12893)当传递无效参数(例如浮点窗口)时,窗口函数中的错误消息更友好 (GH 12669)
切片子类化
DataFrame
定义为返回子类化Series
时,可能返回正常Series
的错误 (GH 11559).str
访问器方法在输入具有name
且结果为DataFrame
或MultiIndex
时可能引发ValueError
的错误 (GH 12617)空 frame 上
DataFrame.last_valid_index()
和DataFrame.first_valid_index()
的错误 (GH 12800)CategoricalIndex.get_loc
返回与常规Index
不同结果的错误 (GH 12531)PeriodIndex.resample
中名称未传播的错误 (GH 12769)date_range
closed
关键字和时区中的错误 (GH 12684)。当输入数据包含时区感知日期时间和时间差时,
pd.concat
引发AttributeError
的错误 (GH 12620)pd.concat
未正确处理空Series
的错误 (GH 11082)当指定
width
为int
时,.plot.bar
对齐的错误 (GH 12979)如果二元运算符的参数是常量,则
fill_value
被忽略的错误 (GH 12723)当使用 bs4 风味解析带有一个标题和一列的表格时,
pd.read_html()
的错误 (GH 9178)当
margins=True
和dropna=True
时,.pivot_table
中的错误,其中空值仍然计入边际计数 (GH 12577)当
dropna=False
时,.pivot_table
中的错误,其中表格索引/列名消失 (GH 12133)当
margins=True
和dropna=False
时,pd.crosstab()
引发错误的错误 (GH 12642)当
name
属性可以是可哈希类型时,Series.name
的错误 (GH 12610).describe()
重置分类列信息的错误 (GH 11558)在时间序列上调用
resample().count()
时,未应用loffset
参数的错误 (GH 12725)pd.read_excel()
现在接受与关键字参数names
关联的列名 (GH 12870)带有
Index
的pd.to_numeric()
返回np.ndarray
而不是Index
的错误 (GH 12777)带有日期时间类似值的
pd.to_numeric()
可能引发TypeError
的错误 (GH 12777)带有标量的
pd.to_numeric()
引发ValueError
的错误 (GH 12777)
贡献者#
共有 60 人为此版本贡献了补丁。名字旁边带有“+”的人是首次贡献补丁。
Andrew Fiore-Gartland +
Bastiaan +
Benoît Vinot +
Brandon Rhodes +
DaCoEx +
Drew Fustin +
Ernesto Freitas +
Filip Ter +
Gregory Livschitz +
Gábor Lipták
Hassan Kibirige +
Iblis Lin
Israel Saeta Pérez +
Jason Wolosonovich +
Jeff Reback
Joe Jevnik
Joris Van den Bossche
Joshua Storck +
Ka Wo Chen
Kerby Shedden
Kieran O’Mahony
Leif Walsh +
Mahmoud Lababidi +
Maoyuan Liu +
Mark Roth +
Matt Wittmann
MaxU +
Maximilian Roos
Michael Droettboom +
Nick Eubank
Nicolas Bonnotte
OXPHOS +
Pauli Virtanen +
Peter Waller +
Pietro Battiston
Prabhjot Singh +
Robin Wilson
Roger Thomas +
Sebastian Bank
Stephen Hoover
Tim Hopper +
Tom Augspurger
WANG Aiyong
Wes Turner
Winand +
Xbar +
Yan Facai +
adneu +
ajenkins-cargometrics +
behzad nouri
chinskiy +
gfyoung
jeps-journal +
jonaslb +
kotrfa +
nileracecrew +
onesandzeroes
rs2 +
sinhrks
tsdlovell +