Pandas-2-2-中文文档-四十三-
Pandas 2.2 中文文档(四十三)
1.5.3 中的新功能(2023 年 1 月 18 日)
这些是 pandas 1.5.3 的更改。请参阅发行说明以获取包括 pandas 其他版本在内的完整更改日志。
修复的回归
-
修复了
Series.isin()中的性能回归,当values为空时(GH 49839) -
修复了
DataFrame.memory_usage()中的回归,在DataFrame为空时显示不必要的FutureWarning(GH 50066) -
在
as_index=False情况下使用时修复了DataFrameGroupBy.transform()中的回归(GH 49834) -
在函数
DataFrame.plot.scatter()中强制回退color作为c的别名,size作为s的别名(GH 49732) -
修复了
SeriesGroupBy.apply()中的回归,在结果为DataFrame时设置了name属性(GH 49907) -
修复了使用
at()索引器设置中的性能回归(GH 49771) -
修复了
to_datetime()中的回归,当解析包含np.nan的float数组时引发ValueError(GH 50237) ## Bug 修复 -
当使用另一个
DataFrame索引一个DataFrame时,复制写实现中的 Bug 导致丢失视图的跟踪(GH 50630) -
在向 Excel 写入器提供未识别的
border-style(例如"hair")时导致Styler.to_excel()出错的 Bug(GH 48649) -
在仅包含
NA值的Series上调用Series.quantile()时出现的 Bug,导致 NumPy 发出警告(GH 50681) -
当多次链式调用
Styler.concat()时出现的 Bug,只有最后一个样式器被连接起来了(GH 49207) -
修复了在 Python 3.11 上实例化继承自
typing.Generic的DataFrame子类时触发UserWarning的 Bug(GH 49649) -
在 NumPy 1.24 或更高版本下,当
DataFrame列具有嵌套元素时,pivot_table()出现的 Bug(GH 50342) -
在具有嵌套数据并且使用 numpy >= 1.25 时,
pandas.testing.assert_series_equal()(以及等效的assert_函数)出现的 Bug(GH 50360) ## Other
注意
如果你正在使用 SQLAlchemy 版本为 1.4.46 或更高的 DataFrame.to_sql()、read_sql()、read_sql_table() 或 read_sql_query(),你可能会看到一个 sqlalchemy.exc.RemovedIn20Warning。在 SQLAlchemy 1.4.x 发布版本中,可以安全地忽略这些警告,因为 pandas 正在向兼容 SQLAlchemy 2.0 迈进。
-
撤销了关于使用整数
Index对Series.__getitem__()和Series.__setitem__()进行切片的行为的弃用(GH 45324);这将保持位置性(GH 49612) -
使用
DataFrame.loc()或DataFrame.iloc()设置值时,引发的FutureWarning已更改为DeprecationWarning(GH 48673) ## 贡献者
共有 19 人为这个版本贡献了补丁。名字后面有“+”符号的人第一次贡献了补丁。
-
Emma Carballal Haire +
-
Irv Lustig
-
JHM Darbyshire
-
Joris Van den Bossche
-
Marc Garcia
-
Marco Edward Gorelli
-
MarcoGorelli
-
Matthew Roeschke
-
MeeseeksMachine
-
Natalia Mokeeva
-
Pandas 开发团队
-
Patrick Hoefler
-
Richard Shadrach
-
Tsvika Shapira +
-
William Ayd
-
aneesh98
-
jakirkham +
-
jbrockmendel
-
silviaovo + ## 修复回归
-
修复了
Series.isin()在values为空时的性能回归(GH 49839) -
修复了在
DataFrame为空时,DataFrame.memory_usage()显示不必要的FutureWarning的回归 (GH 50066) -
修复了在与
as_index=False一起使用时DataFrameGroupBy.transform()的回归(GH 49834) -
强制将
color作为c的别名,将size作为s的别名,并在DataFrame.plot.scatter()函数中恢复使用(GH 49732) -
修复了
SeriesGroupBy.apply()在结果为DataFrame时设置了name属性的回归 (GH 49907) -
修复了使用
at()索引器时的性能回归(GH 49771) -
修复了在解析包含
np.nan的float数组时,to_datetime()引发ValueError的回归 (GH 50237)
Bug 修复
-
在复制写实现中存在 Bug,在用另一个
DataFrame索引一个DataFrame时丢失了视图的跟踪 (GH 50630) -
在
Styler.to_excel()中存在 Bug,当 Excel 写入器提供了无法识别的border-style(例如"hair")时会导致错误 (GH 48649) -
在
Series.quantile()中存在 Bug,在Series只有NA值时会从 NumPy 发出警告 (GH 50681) -
在链式调用多个
Styler.concat()时存在 Bug,只有最后一个样式器被连接起来了 (GH 49207) -
修复了当实例化继承自
typing.Generic的DataFrame子类时,在 Python 3.11 上触发UserWarning的 Bug (GH 49649) -
在使用 NumPy 1.24 或更高版本时,
DataFrame列具有嵌套元素时,pivot_table()存在 Bug (GH 50342) -
在具有嵌套数据并且使用 numpy >= 1.25 时,
pandas.testing.assert_series_equal()(以及等效的assert_函数)存在 Bug (GH 50360)
其他
注意
如果你正在使用 SQLAlchemy 1.4.46 或更高版本与 DataFrame.to_sql(), read_sql(), read_sql_table(), 或 read_sql_query(),你可能会看到 sqlalchemy.exc.RemovedIn20Warning。对于 SQLAlchemy 1.4.x 版本,可以安全地忽略这些警告,因为 pandas 正在努力实现与 SQLAlchemy 2.0 的兼容性。
-
撤销了对
Series.__getitem__()和Series.__setitem__()对整数索引Index切片的废弃警告(GH 45324);此将保持位置不变(GH 49612) -
尝试使用
DataFrame.loc()或DataFrame.iloc()进行就地设置值时,引发的FutureWarning已更改为DeprecationWarning(GH 48673)
贡献者
总共有 19 人为此版本提供了补丁。名字后面有“+”符号的人第一次为此版本提供了补丁。
-
Emma Carballal Haire +
-
Irv Lustig
-
JHM Darbyshire
-
Joris Van den Bossche
-
Marc Garcia
-
Marco Edward Gorelli
-
MarcoGorelli
-
Matthew Roeschke
-
MeeseeksMachine
-
Natalia Mokeeva
-
Pandas 开发团队
-
Patrick Hoefler
-
Richard Shadrach
-
Tsvika Shapira +
-
William Ayd
-
aneesh98
-
jakirkham +
-
jbrockmendel
-
silviaovo +
1.5.2 版本的新功能(2022 年 11 月 21 日)
这些是 pandas 1.5.2 版本的变化。详见发布说明以获取包括其他版本的完整更新日志。
修复的回归
-
修复了扩展数组数据类型的
MultiIndex.join()中的回归(GH 49277) -
修复了具有数值数据类型并且指定
value=None时Series.replace()引发RecursionError的回归 (GH 45725) -
修复了带有不同数据类型的
MultiIndex列的DataFrame的算术运算中的回归(GH 49769) -
修复了
DataFrame.plot()中的回归,如果使用 Matplotlib 3.6+,则无法通过colormap参数传递Colormap实例(GH 49374) -
修复了当
CustomBusinessDay频率和带有时区的start日期时,date_range()返回无效周期集的回归 (GH 49441) -
修复了 groupby 操作中的性能退化(GH 49676)
-
修复了
Timedelta构造函数中的回归,当子类化Timedelta时返回错误类型的对象(GH 49579) ## Bug 修复 -
在某些链式索引情况下,修复了 Copy-on-Write 实现中丢失视图跟踪的 Bug(GH 48996)
-
修复了
Styler.to_excel()中的内存泄漏(GH 49751) ## 其他 -
恢复了
color作为c的别名以及size作为s的别名在DataFrame.plot.scatter()函数中的使用(GH 49732) ## 贡献者
总共有 20 人为此版本提供了补丁。在其名字后面带有“+”的人第一次为此提供了补丁。
-
Ambuj Pawar +
-
Dennis Chukwunta
-
Douglas Lohmann +
-
Hatim Zahid +
-
Joris Van den Bossche
-
KotlinIsland +
-
Marc Garcia
-
Marco Edward Gorelli
-
MarcoGorelli
-
Matthew Roeschke
-
MeeseeksMachine
-
Natalia Mokeeva +
-
Noa Tamir
-
Pandas 开发团队
-
Patrick Hoefler
-
Richard Shadrach
-
Xnot +
-
Zachary Moon +
-
jbrockmendel
-
krasch + ## 修复回归
-
修复了对扩展数组数据类型的
MultiIndex.join()的回归(GH 49277) -
修复了
Series.replace()在数值数据类型和指定value=None时引发RecursionError的回归(GH 45725) -
修复了对具有不同数据类型的
MultiIndex列的DataFrame进行算术运算的回归(GH 49769) -
修复了在使用 Matplotlib 3.6+ 时阻止
DataFrame.plot()中传递Colormap实例使用colormap参数的回归(GH 49374) -
修复了
date_range()对CustomBusinessDay频率和带时区的start日期返回无效周期集的回归(GH 49441) -
修复了分组操作中的性能回归(GH 49676)
-
修复了在子类化
Timedelta时Timedelta构造函数返回错误类型对象的回归(GH 49579)
错误修复
其他
- 在函数
DataFrame.plot.scatter()中,恢复了color作为c的别名和size作为s的别名的用法(GH 49732)
贡献者
一共有 20 人为这次发布贡献了补丁。名字后面带有“+”的人是第一次贡献补丁的。
-
安布吉·帕瓦尔 +
-
丹尼斯·楚昆塔
-
道格拉斯·洛曼 +
-
哈蒂姆·扎希德 +
-
乔里斯·范登博斯
-
Kotlin 岛 +
-
马克·加西亚
-
马可·爱德华·戈雷利
-
马可·戈雷利
-
马修·罗斯奇克
-
米西克斯机器
-
娜塔莉娅·莫凯娃 +
-
诺亚·塔米尔
-
熊猫开发团队
-
帕特里克·霍夫勒
-
理查德·沙德拉赫
-
Xnot +
-
扎卡里·穆恩 +
-
杰布洛克曼德尔
-
克拉什 +
1.5.1 版本中的新功能(2022 年 10 月 19 日)
这些是 pandas 1.5.1 中的变化。请参阅发布说明以获取包括其他版本的 pandas 的完整更改日志。
使用分类分组器进行groupby的行为 (GH 48645)
在 1.5 版本之前的 pandas 版本中,使用dropna=False的groupby仍会在分组器是分类数据类型时删除 NA 值。1.5 中尝试了修复此问题,但是引入了一个回归,即向groupby传递observed=False和dropna=False将导致仅观察到的类别。发现修复dropna=False错误的补丁与observed=False不兼容,并决定最好的解决方案是恢复正确的observed=False行为,以重新引入dropna=False错误。
In [1]: df = pd.DataFrame(
...: {
...: "x": pd.Categorical([1, None], categories=[1, 2, 3]),
...: "y": [3, 4],
...: }
...: )
...:
In [2]: df
Out[2]:
x y
0 1 3
1 NaN 4
1.5.0 行为:
In [3]: # Correct behavior, NA values are not dropped
df.groupby("x", observed=True, dropna=False).sum()
Out[3]:
y
x
1 3
NaN 4
In [4]: # Incorrect behavior, only observed categories present
df.groupby("x", observed=False, dropna=False).sum()
Out[4]:
y
x
1 3
NaN 4
1.5.1 行为:
# Incorrect behavior, NA values are dropped
In [3]: df.groupby("x", observed=True, dropna=False).sum()
Out[3]:
y
x
1 3
NaN 4
# Correct behavior, unobserved categories present (NA values still dropped)
In [4]: df.groupby("x", observed=False, dropna=False).sum()
Out[4]:
y
x
1 3
2 0
3 0
NaN 4
``` ## 修复的回归
+ 修复了`Series.__setitem__()`中的回归,将`None`转换为`NaN`以适应对象数据类型 ([GH 48665](https://github.com/pandas-dev/pandas/issues/48665))
+ 修复了`DataFrame.loc()`中的回归,当将值设置为所有`True`索引器的`DataFrame`时 ([GH 48701](https://github.com/pandas-dev/pandas/issues/48701))
+ `read_csv()`中的回归导致在使用已经读取的 UTF-8 文件句柄时引发`EmptyDataError` ([GH 48646](https://github.com/pandas-dev/pandas/issues/48646))
+ `to_datetime()`中的回归,当`utc=True`并且`arg`包含时区不明确和明确的参数时引发`ValueError` ([GH 48678](https://github.com/pandas-dev/pandas/issues/48678))
+ 修复了`DataFrame.loc()`中的回归,在设置空的`DataFrame`时引发`FutureWarning` ([GH 48480](https://github.com/pandas-dev/pandas/issues/48480))
+ 修复了`DataFrame.describe()`中的回归,在结果包含`NA`时引发`TypeError`([GH 48778](https://github.com/pandas-dev/pandas/issues/48778))
+ 修复了`DataFrame.plot()`中的回归,忽略了对`kind="scatter"`的无效`colormap`([GH 48726](https://github.com/pandas-dev/pandas/issues/48726))
+ 修复了`MultiIndex.values()`重置底层`Index`对象的`freq`属性的回归问题([GH 49054](https://github.com/pandas-dev/pandas/issues/49054))
+ 修复了在`na_sentinel`不是`None`且`sort=False`时`factorize()`的性能回归问题([GH 48620](https://github.com/pandas-dev/pandas/issues/48620))
+ 修复了`DataFrame.to_sql()`中提供的表名与实际在数据库中使用的表名不匹配时导致的`AttributeError`警告回归问题([GH 48733](https://github.com/pandas-dev/pandas/issues/48733))
+ 修复了当`arg`是带有纳秒的日期字符串且`format`包含`%f`时`to_datetime()`引发`ValueError`的回归问题([GH 48767](https://github.com/pandas-dev/pandas/issues/48767))
+ 修复了当`check_like=True`时`testing.assert_frame_equal()`对带有`Categorical`和`MultiIndex`的情况的回归问题([GH 48975](https://github.com/pandas-dev/pandas/issues/48975))
+ 修复了对`datetime64[ns]`类型和`inplace=True`时`DataFrame.fillna()`替换错误值的回归问题([GH 48863](https://github.com/pandas-dev/pandas/issues/48863))
+ 修复了当`axis=1`时`DataFrameGroupBy.size()`不返回 Series 的问题([GH 48738](https://github.com/pandas-dev/pandas/issues/48738))
+ 修复了当用户定义函数在空数据帧上调用时`DataFrameGroupBy.apply()`的回归问题([GH 47985](https://github.com/pandas-dev/pandas/issues/47985))
+ 修复了通过关键字参数传递非零`axis`时`DataFrame.apply()`的回归问题([GH 48656](https://github.com/pandas-dev/pandas/issues/48656))
+ 修复了当 grouper 是可空数据类型(例如`Int64`)或 PyArrow 支持的字符串数组,包含空值,并且`dropna=False`时,`Series.groupby()`和`DataFrame.groupby()`中的回归([GH 48794](https://github.com/pandas-dev/pandas/issues/48794))
+ 修复了`Series.isin()`中的性能回归,与不匹配的 dtype 相匹配([GH 49162](https://github.com/pandas-dev/pandas/issues/49162))
+ 修复了当文件名指定为`bytes`时,`DataFrame.to_parquet()`中的回归,引发异常([GH 48944](https://github.com/pandas-dev/pandas/issues/48944))
+ 修复了`ExcelWriter`中的回归,其中不再能够设置`book`属性;但是,设置此属性现已不推荐使用,这种能力将在 pandas 的将来版本中删除([GH 48780](https://github.com/pandas-dev/pandas/issues/48780))
+ 修复了在使用`method="spearman"`计算关联时,`DataFrame.corrwith()`中的回归,出现绑定数据的情况([GH 48826](https://github.com/pandas-dev/pandas/issues/48826)) ## Bug fixes
+ 在`Series.__getitem__()`中存在错误,对于整数键和布尔`Index`不再回退到位置性([GH 48653](https://github.com/pandas-dev/pandas/issues/48653))
+ 在`DataFrame.to_hdf()`中存在错误,使用布尔索引引发`AssertionError`([GH 48667](https://github.com/pandas-dev/pandas/issues/48667))
+ 在具有非匹配`NA`的扩展数组的`testing.assert_index_equal()`中存在错误,会引发`ValueError`([GH 48608](https://github.com/pandas-dev/pandas/issues/48608))
+ 在将 datetime 列设置为索引时,`DataFrame.pivot_table()`中存在错误,会引发意外的`FutureWarning`([GH 48683](https://github.com/pandas-dev/pandas/issues/48683))
+ 修复了在`DataFrame`上调用`DataFrame.sort_values()`时发出不必要的`FutureWarning`的错误,当列为布尔稀疏列时([GH 48784](https://github.com/pandas-dev/pandas/issues/48784))
+ 修复了在 `arrays.ArrowExtensionArray` 中使用比较运算符与无效对象不会引发 `NotImplementedError` 的错误([GH 48833](https://github.com/pandas-dev/pandas/issues/48833)) ## 其他
+ 当检查具有关于参数变为仅关键字的警告的函数时,避免显示已弃用的签名([GH 48692](https://github.com/pandas-dev/pandas/issues/48692)) ## 贡献者
总共有 16 人为这个版本贡献了补丁。名字后面带有“+”的人第一次贡献了补丁。
+ Amay Patel +
+ Deepak Sirohiwal +
+ Dennis Chukwunta
+ Gaurav Sheni
+ Himanshu Wagh +
+ Lorenzo Vainigli +
+ Marc Garcia
+ Marco Edward Gorelli
+ Matthew Roeschke
+ MeeseeksMachine
+ Noa Tamir
+ Pandas 开发团队
+ Patrick Hoefler
+ Richard Shadrach
+ Shantanu
+ Torsten Wörtwein ## 使用分类分组器的 `groupby` 行为 ([GH 48645](https://github.com/pandas-dev/pandas/issues/48645))
在 pandas 版本 1.5 之前,使用 `dropna=False` 的 `groupby` 在分组器为分类数据类型时仍会删除 NA 值。在 1.5 中尝试修复了这个问题,但引入了一个新问题,即将 `observed=False` 和 `dropna=False` 传递给 `groupby` 会导致只有观察到的类别。发现修复 `dropna=False` 错误的补丁与 `observed=False` 不兼容,决定以恢复正确的 `observed=False` 行为为代价,重新引入 `dropna=False` 错误。
```py
In [1]: df = pd.DataFrame(
...: {
...: "x": pd.Categorical([1, None], categories=[1, 2, 3]),
...: "y": [3, 4],
...: }
...: )
...:
In [2]: df
Out[2]:
x y
0 1 3
1 NaN 4
1.5.0 行为:
In [3]: # Correct behavior, NA values are not dropped
df.groupby("x", observed=True, dropna=False).sum()
Out[3]:
y
x
1 3
NaN 4
In [4]: # Incorrect behavior, only observed categories present
df.groupby("x", observed=False, dropna=False).sum()
Out[4]:
y
x
1 3
NaN 4
1.5.1 行为:
# Incorrect behavior, NA values are dropped
In [3]: df.groupby("x", observed=True, dropna=False).sum()
Out[3]:
y
x
1 3
NaN 4
# Correct behavior, unobserved categories present (NA values still dropped)
In [4]: df.groupby("x", observed=False, dropna=False).sum()
Out[4]:
y
x
1 3
2 0
3 0
NaN 4
修复的回归问题
-
修复了在
Series.__setitem__()中将None转换为NaN(对于对象数据类型)的回归问题(GH 48665) -
修复了在将所有
True索引器设置为DataFrame时,DataFrame.loc()中的回归问题(GH 48701) -
修复了在使用已经读取的 UTF-8 文件句柄时,在
read_csv()中引发EmptyDataError的回归问题(GH 48646) -
当
utc=True且arg包含时区敏感和感知参数时,to_datetime()中的回归引发了ValueError(GH 48678) -
修复了
DataFrame.loc()设置空DataFrame时引发FutureWarning的回归(GH 48480) -
修复了
DataFrame.describe()在结果包含NA时引发TypeError的回归(GH 48778) -
修复了
DataFrame.plot()在kind="scatter"时忽略无效colormap的回归(GH 48726) -
修复了
MultiIndex.values()中重置底层Index对象的freq属性的回归(GH 49054) -
修复了
factorize()在na_sentinel不是None且sort=False时的性能回归(GH 48620) -
修复了在警告发出时提供的表名与实际在数据库中使用的表名不匹配时引发的
AttributeError回归(DataFrame.to_sql())(GH 48733) -
修复了
to_datetime()在arg是带有纳秒且format包含%f的日期字符串时引发ValueError的回归(GH 48767) -
修复了
testing.assert_frame_equal()在MultiIndex中使用Categorical和check_like=True时引发的回归 (GH 48975) -
修复了
DataFrame.fillna()替换datetime64[ns]类型和inplace=True时的错误值的回归(GH 48863) -
修复了
DataFrameGroupBy.size()在axis=1时未返回 Series 的问题(GH 48738) -
修复了
DataFrameGroupBy.apply()中的回归问题,当用户定义函数在空数据帧上调用时(GH 47985) -
修复了
DataFrame.apply()中的回归问题,当通过关键字参数传递非零axis时引发错误(GH 48656) -
修复了
Series.groupby()和DataFrame.groupby()中的回归问题,当分组器是可为空数据类型(例如Int64)或 PyArrow 支持的字符串数组时,包含空值,并且dropna=False时(GH 48794) -
修复了
Series.isin()中的性能回归问题,其数据类型不匹配(GH 49162) -
修复了
DataFrame.to_parquet()中的回归问题,在指定文件名为bytes时引发错误(GH 48944) -
修复了
ExcelWriter中的回归问题,其中book属性不再设置;但是,设置此属性现已被弃用,并且将在 pandas 的将来版本中删除此功能(GH 48780) -
修复了
DataFrame.corrwith()中的回归问题,在使用method="spearman"计算相关性时,处理了绑定数据的问题(GH 48826)
Bug 修复
-
Series.__getitem__()中的 Bug 未对整数键和布尔型Index进行位置回退(GH 48653) -
DataFrame.to_hdf()中的 Bug 引发了带有布尔索引的AssertionError(GH 48667) -
testing.assert_index_equal()中针对非匹配NA报错ValueError的 Bug (GH 48608) -
当将日期时间列设置为索引时,
DataFrame.pivot_table()引发意外的FutureWarning的 Bug (GH 48683) -
当在具有布尔稀疏列的
DataFrame上调用DataFrame.sort_values()时,不必要地引发FutureWarning的 Bug (GH 48784) -
当与无效对象比较运算符时,
arrays.ArrowExtensionArray不会引发NotImplementedError的 Bug (GH 48833)
其他
- 当警告指出参数将成为仅限关键字参数时,避免显示不推荐使用的签名 (GH 48692)
贡献者
总共有 16 人为此版本贡献了补丁。带有“+”标记的人第一次为此贡献了补丁。
-
Amay Patel +
-
Deepak Sirohiwal +
-
Dennis Chukwunta
-
Gaurav Sheni
-
Himanshu Wagh +
-
Lorenzo Vainigli +
-
Marc Garcia
-
Marco Edward Gorelli
-
Matthew Roeschke
-
MeeseeksMachine
-
Noa Tamir
-
Pandas 开发团队
-
Patrick Hoefler
-
Richard Shadrach
-
Shantanu
-
Torsten Wörtwein
1.5.0 的新功能(2022 年 9 月 19 日)
这些是 pandas 1.5.0 的更改。查看发布说明以获取包括其他版本在内的完整更改日志。
增强
pandas-stubs
pandas-stubs库现在由 pandas 开发团队支持,为 pandas API 提供类型存根。请访问pandas-dev/pandas-stubs获取更多信息。
我们感谢 VirtusLab 和 Microsoft 对pandas-stubs的最初和重要贡献 ### 本机 PyArrow 支持的 ExtensionArray
安装了Pyarrow后,用户现在可以创建由pyarrow.ChunkedArray和pyarrow.DataType支持的 pandas 对象。
dtype参数可以接受带有pyarrow的pyarrow 数据类型的字符串,例如"int64[pyarrow]"或对于接受参数的 pyarrow 数据类型,可以使用使用pyarrow.DataType初始化的ArrowDtype。
In [1]: import pyarrow as pa
In [2]: ser_float = pd.Series([1.0, 2.0, None], dtype="float32[pyarrow]")
In [3]: ser_float
Out[3]:
0 1.0
1 2.0
2 <NA>
dtype: float[pyarrow]
In [4]: list_of_int_type = pd.ArrowDtype(pa.list_(pa.int64()))
In [5]: ser_list = pd.Series([[1, 2], [3, None]], dtype=list_of_int_type)
In [6]: ser_list
Out[6]:
0 [1\. 2.]
1 [ 3\. nan]
dtype: list<item: int64>[pyarrow]
In [7]: ser_list.take([1, 0])
Out[7]:
1 [ 3\. nan]
0 [1\. 2.]
dtype: list<item: int64>[pyarrow]
In [8]: ser_float * 5
Out[8]:
0 5.0
1 10.0
2 <NA>
dtype: float[pyarrow]
In [9]: ser_float.mean()
Out[9]: 1.5
In [10]: ser_float.dropna()
Out[10]:
0 1.0
1 2.0
dtype: float[pyarrow]
大多数操作都受支持,并已使用pyarrow compute函数进行了实现。我们建议安装最新版本的 PyArrow 以访问最近实现的计算函数。
警告
此功能是实验性的,API 可能在未来的发布中发生变化而没有警告。 ### DataFrame 交换协议实现
Pandas 现在实现了 DataFrame 交换 API 规范。查看data-apis.org/dataframe-protocol/latest/index.html上的 API 的完整详细信息
协议由两部分组成:
-
新方法
DataFrame.__dataframe__()可生成交换对象。它有效地“导出”pandas dataframe 作为交换对象,因此任何其他实现了该协议的库都可以“导入”该 dataframe,而不需要知道有关生产者的任何信息,只需知道它生成了一个交换对象即可。 -
新函数
pandas.api.interchange.from_dataframe()可以接受任何符合库的任意交换对象,并构造出一个 pandas DataFrame。 ### Styler
最显着的发展是新方法Styler.concat(),它允许在数据上添加自定义页脚行以可视化额外的计算,例如总计和计数等(GH 43875, GH 46186)
此外,还有一种替代输出方法Styler.to_string(),允许使用 Styler 的格式化方法来创建,例如 CSV 文件(GH 44502)。
还提供了一个新功能Styler.relabel_index(),可提供完全定制索引或列标题的显示(GH 47864)。
次要功能改进包括:
参数group_keys已添加到方法DataFrame.resample()中。与DataFrame.groupby()一样,此参数控制在使用Resampler.apply()进行重新采样时,是否将每个组添加到索引中。
警告
不指定group_keys参数将保留以前的行为,并在通过指定group_keys=False更改结果时发出警告。在 pandas 的未来版本中,不指定group_keys将默认为与group_keys=False相同的行为。
In [11]: df = pd.DataFrame(
....: {'a': range(6)},
....: index=pd.date_range("2021-01-01", periods=6, freq="8H")
....: )
....:
In [12]: df.resample("D", group_keys=True).apply(lambda x: x)
Out[12]:
a
2021-01-01 2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [13]: df.resample("D", group_keys=False).apply(lambda x: x)
Out[13]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
之前,结果索引会依赖于apply返回的值,如下例所示。
In [1]: # pandas 1.3
In [2]: df.resample("D").apply(lambda x: x)
Out[2]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [3]: df.resample("D").apply(lambda x: x.reset_index())
Out[3]:
index a
2021-01-01 0 2021-01-01 00:00:00 0
1 2021-01-01 08:00:00 1
2 2021-01-01 16:00:00 2
2021-01-02 0 2021-01-02 00:00:00 3
1 2021-01-02 08:00:00 4
2 2021-01-02 16:00:00 5
``` ### from_dummies
添加了新函数`from_dummies()`以将虚拟编码的`DataFrame`转换为分类`DataFrame`。
```py
In [11]: import pandas as pd
In [12]: df = pd.DataFrame({"col1_a": [1, 0, 1], "col1_b": [0, 1, 0],
....: "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
....: "col2_c": [0, 0, 1]})
....:
In [13]: pd.from_dummies(df, sep="_")
Out[13]:
col1 col2
0 a b
1 b a
2 a c
``` ### 写入 ORC 文件
新的方法`DataFrame.to_orc()`允许写入 ORC 文件([GH 43864](https://github.com/pandas-dev/pandas/issues/43864))。
此功能依赖于[pyarrow](http://arrow.apache.org/docs/python/)库。有关更多详细信息,请参阅 ORC IO 文档。
警告
+ 由于一些问题导致的,*强烈建议*使用 conda 安装 pyarrow。
+ `to_orc()`需要 pyarrow>=7.0.0。
+ `to_orc()`在 Windows 上尚不支持,你可以在安装可选依赖项中找到有效的环境。
+ 有关支持的 dtype,请参阅[Arrow 中支持的 ORC 特性](https://arrow.apache.org/docs/cpp/orc.html#data-types)。
+ 当 DataFrame 转换为 ORC 文件时,datetime 列中的时区目前不被保留。
```py
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
df.to_orc("./out.orc")
``` ### 直接从 TAR 归档文件中读取
IO 方法如`read_csv()`或`DataFrame.to_json()`现在允许直接在 TAR 归档文件上读取和写入([GH 44787](https://github.com/pandas-dev/pandas/issues/44787))。
```py
df = pd.read_csv("./movement.tar.gz")
# ...
df.to_csv("./out.tar.gz")
这支持.tar、.tar.gz、.tar.bz和.tar.xz2归档。所使用的压缩方法从文件名中推断出来。如果无法推断出压缩方法,请使用compression参数:
df = pd.read_csv(some_file_obj, compression={"method": "tar", "mode": "r:gz"}) # noqa F821
(mode是tarfile.open的模式之一:docs.python.org/3/library/tarfile.html#tarfile.open) ### read_xml 现在支持dtype、converters和parse_dates
与其他 IO 方法类似,pandas.read_xml()现在支持为列指定特定的 dtype,应用转换器方法和解析日期(GH 43567)。
In [14]: from io import StringIO
In [15]: xml_dates = """<?xml version='1.0' encoding='utf-8'?>
....: <data>
....: <row>
....: <shape>square</shape>
....: <degrees>00360</degrees>
....: <sides>4.0</sides>
....: <date>2020-01-01</date>
....: </row>
....: <row>
....: <shape>circle</shape>
....: <degrees>00360</degrees>
....: <sides/>
....: <date>2021-01-01</date>
....: </row>
....: <row>
....: <shape>triangle</shape>
....: <degrees>00180</degrees>
....: <sides>3.0</sides>
....: <date>2022-01-01</date>
....: </row>
....: </data>"""
....:
In [16]: df = pd.read_xml(
....: StringIO(xml_dates),
....: dtype={'sides': 'Int64'},
....: converters={'degrees': str},
....: parse_dates=['date']
....: )
....:
In [17]: df
Out[17]:
shape degrees sides date
0 square 00360 4 2020-01-01
1 circle 00360 <NA> 2021-01-01
2 triangle 00180 3 2022-01-01
In [18]: df.dtypes
Out[18]:
shape object
degrees object
sides Int64
date datetime64[ns]
dtype: object
``` ### read_xml 现在支持大型 XML 使用`iterparse`
对于可以达到数百兆到几十吉字节的非常大的 XML 文件,`pandas.read_xml()` 现在支持使用 [lxml's iterparse](https://lxml.de/3.2/parsing.html#iterparse-and-iterwalk) 和 [etree's iterparse](https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse) 进行解析,这些方法是内存高效的方法,可以遍历 XML 树并提取特定元素和属性,而无需将整个树保留在内存中 ([GH 45442](https://github.com/pandas-dev/pandas/issues/45442))。
```py
In [1]: df = pd.read_xml(
... "/path/to/downloaded/enwikisource-latest-pages-articles.xml",
... iterparse = {"page": ["title", "ns", "id"]})
... )
df
Out[2]:
title ns id
0 Gettysburg Address 0 21450
1 Main Page 0 42950
2 Declaration by United Nations 0 8435
3 Constitution of the United States of America 0 8435
4 Declaration of Independence (Israel) 0 17858
... ... ... ...
3578760 Page:Black cat 1897 07 v2 n10.pdf/17 104 219649
3578761 Page:Black cat 1897 07 v2 n10.pdf/43 104 219649
3578762 Page:Black cat 1897 07 v2 n10.pdf/44 104 219649
3578763 The History of Tom Jones, a Foundling/Book IX 0 12084291
3578764 Page:Shakespeare of Stratford (1926) Yale.djvu/91 104 21450
[3578765 rows x 3 columns]
``` ### 写时复制
添加了一个名为 `copy_on_write` 的新特性 ([GH 46958](https://github.com/pandas-dev/pandas/issues/46958))。写时复制确保从任何方式派生的任何 DataFrame 或 Series 始终表现为副本。写时复制禁止更新除应用方法的对象之外的任何其他对象。
通过以下方式可以启用写时复制:
```py
pd.set_option("mode.copy_on_write", True)
pd.options.mode.copy_on_write = True
或者,可以通过以下方式在本地启用写时复制:
with pd.option_context("mode.copy_on_write", True):
...
在没有启用写时复制的情况下,当更新从此 DataFrame 派生的子 DataFrame 时,父 DataFrame 会被更新。
In [19]: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
In [20]: view = df["foo"]
In [21]: view.iloc[0]
Out[21]: 1
In [22]: df
Out[22]:
foo bar
0 1 1
1 2 1
2 3 1
启用写时复制后,df 不再更新:
In [23]: with pd.option_context("mode.copy_on_write", True):
....: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
....: view = df["foo"]
....: view.iloc[0]
....: df
....:
可以在此处找到更详细的解释。 ### 其他增强
-
当
arg是字典但na_action不是None或'ignore'时,Series.map()现在会抛出异常 (GH 46588) -
MultiIndex.to_frame()现在支持参数allow_duplicates,如果缺少或为 False,则在存在重复标签时会引发异常 (GH 45245) -
StringArray的构造函数现在除了字符串和pandas.NA外,还接受包含 nan-like (None,np.nan) 的数组作为values参数的数组样本。(GH 40839) -
改进了
CategoricalIndex中categories的渲染效果 (GH 45218) -
DataFrame.plot()现在允许subplots参数是指定列组的可迭代列表,以便将列分组在同一个子图中(GH 29688). -
to_numeric()现在在向下转换会生成无法表示为 float32 的值时,会保留 float64 数组(GH 43693) -
Series.reset_index()和DataFrame.reset_index()现在支持参数allow_duplicates(GH 44410) -
DataFrameGroupBy.min()、SeriesGroupBy.min()、DataFrameGroupBy.max()和SeriesGroupBy.max()现在支持使用engine关键字进行 Numba 执行(GH 45428) -
read_csv()现在支持将defaultdict作为dtype参数(GH 41574) -
DataFrame.rolling()和Series.rolling()现在支持具有固定长度窗口的step参数(GH 15354) -
实现了
bool类型的Index,将 bool 类型的类数组传递给pd.Index现在将保留bool类型,而不是转换为object(GH 45061) -
实现了复杂类型的
Index,将复杂类型的类数组传递给pd.Index现在将保留复杂类型,而不是转换为object(GH 45845) -
具有
IntegerDtype的Series和DataFrame现在支持按位运算(GH 34463) -
为
DateOffset添加了milliseconds字段支持(GH 43371) -
如果填充值可以在不丢失精度的情况下转换,
DataFrame.where()尝试保持DataFrame的 dtype (GH 45582) -
DataFrame.reset_index()现在接受一个names参数,用于重命名索引名称 (GH 6878) -
concat()现在在levels给定但keys为 None 时会抛出异常(GH 46653) -
concat()现在在levels包含重复值时会抛出异常(GH 46653) -
对
DataFrame.corr()、DataFrame.corrwith()、DataFrame.cov()、DataFrame.idxmin()、DataFrame.idxmax()、DataFrameGroupBy.idxmin()、DataFrameGroupBy.idxmax()、DataFrameGroupBy.var()、SeriesGroupBy.var()、DataFrameGroupBy.std()、SeriesGroupBy.std()、DataFrameGroupBy.sem()、SeriesGroupBy.sem()和DataFrameGroupBy.quantile()添加了numeric_only参数(GH 46560) -
当使用不调度到
pyarrow.compute方法的方法时,现在会抛出errors.PerformanceWarning,具有string[pyarrow]dtype(GH 42613, GH 46725) -
对
DataFrame.join()添加了validate参数(GH 46622) -
在
Resampler.sum()、Resampler.prod()、Resampler.min()、Resampler.max()、Resampler.first()和Resampler.last()中添加了numeric_only参数(GH 46442) -
ExponentialMovingWindow中的times参数现在接受np.timedelta64(GH 47003) -
DataError,SpecificationError,SettingWithCopyError,SettingWithCopyWarning,NumExprClobberingError,UndefinedVariableError,IndexingError,PyperclipException,PyperclipWindowsException,CSSWarning,PossibleDataLossError,ClosedFileError,IncompatibilityWarning,AttributeConflictWarning,DatabaseError,PossiblePrecisionLoss,ValueLabelTypeMismatch,InvalidColumnName, 和CategoricalConversionWarning现在在pandas.errors(GH 27656) 中公开。 -
向
testing.assert_series_equal()添加了check_like参数(GH 47247) -
增加对扩展数组数据类型的
DataFrameGroupBy.ohlc()和SeriesGroupBy.ohlc()的支持(GH 37493) -
允许使用
read_sas()读取压缩的 SAS 文件(例如.sas7bdat.gz文件) -
pandas.read_html()现在支持从表格单元格中提取链接(GH 13141) -
DatetimeIndex.astype()现在支持将时区无关的索引转换为datetime64[s]、datetime64[ms]和datetime64[us],以及将时区感知的索引转换为相应的datetime64[unit, tzname]类型(GH 47579) -
Series的缩减器(例如min、max、sum、mean)现在在提供了数字类型且numeric_only=True时将成功操作;以前会引发NotImplementedError(GH 47500) -
RangeIndex.union()现在如果结果值等间隔,则可以返回一个RangeIndex而不是一个Int64Index(GH 47557,GH 43885) -
DataFrame.compare()现在接受一个参数result_names,允许用户指定正在比较的左右 DataFrame 的结果名称。默认情况下为'self'和'other'(GH 44354) -
DataFrame.quantile()现在获得了一个method参数,可以接受table来评估多列分位数(GH 43881) -
Interval现在支持检查一个区间是否包含在另一个区间内(GH 46613) -
在
Series.set_axis()和DataFrame.set_axis()中添加了copy关键字,允许用户在不必复制基础数据的情况下在新对象上设置轴(GH 47932) -
方法
ExtensionArray.factorize()接受use_na_sentinel=False来确定如何处理空值(GH 46601) -
Dockerfile现在为 pandas 开发安装了一个专用的pandas-dev虚拟环境,而不是使用base环境([GH 48427](https://github.com/pandas-dev/pandas/issues/48427)) ## 显着的错误修复
这些是可能具有显着行为变化的错误修复。
使用dropna=True与groupby转换
转换是一个其结果与其输入大小相同的操作。当结果是DataFrame或Series时,还要求结果的索引与输入的索引匹配。在 pandas 1.4 中,使用带有组中空值的DataFrameGroupBy.transform()或SeriesGroupBy.transform()并且dropna=True会导致不正确的结果。通过下面的示例演示,不正确的结果要么包含不正确的值,要么结果的索引与输入不匹配。
In [24]: df = pd.DataFrame({'a': [1, 1, np.nan], 'b': [2, 3, 4]})
旧行为:
In [3]: # Value in the last row should be np.nan
df.groupby('a', dropna=True).transform('sum')
Out[3]:
b
0 5
1 5
2 5
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[3]:
b
0 5
1 5
In [3]: # The value in the last row is np.nan interpreted as an integer
df.groupby('a', dropna=True).transform('ffill')
Out[3]:
b
0 2
1 3
2 -9223372036854775808
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x)
Out[3]:
b
0 2
1 3
新行为:
In [25]: df.groupby('a', dropna=True).transform('sum')
Out[25]:
b
0 5.0
1 5.0
2 NaN
In [26]: df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[26]:
b
0 5.0
1 5.0
2 NaN
In [27]: df.groupby('a', dropna=True).transform('ffill')
Out[27]:
b
0 2.0
1 3.0
2 NaN
In [28]: df.groupby('a', dropna=True).transform(lambda x: x)
Out[28]:
b
0 2.0
1 3.0
2 NaN
``` ### 使用`iso_dates=True`的`to_json()`序列化 tz-naive Timestamps
`DataFrame.to_json()`, `Series.to_json()`和`Index.to_json()`会不正确地将带有 tz-naive Timestamps 的 DatetimeArrays/DatetimeIndexes 本地化为 UTC。 ([GH 38760](https://github.com/pandas-dev/pandas/issues/38760))
请注意,此补丁未修复将 tz-aware Timestamps 本地化为 UTC 的问题。 (相关问题[GH 12997](https://github.com/pandas-dev/pandas/issues/12997))
*旧行为*
```py
In [32]: index = pd.date_range(
....: start='2020-12-28 00:00:00',
....: end='2020-12-28 02:00:00',
....: freq='1H',
....: )
....:
In [33]: a = pd.Series(
....: data=range(3),
....: index=index,
....: )
....:
In [4]: from io import StringIO
In [5]: a.to_json(date_format='iso')
Out[5]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
In [6]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[6]: array([False, False, False])
新行为
In [34]: from io import StringIO
In [35]: a.to_json(date_format='iso')
Out[35]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
# Roundtripping now works
In [36]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[36]: array([ True, True, True])
``` ### 使用`observed=True`的`DataFrameGroupBy.value_counts`处理非分组分类列
调用`DataFrameGroupBy.value_counts()`时,如果使用 `observed=True`,会错误地删除非观察到的非分组列的类别([GH 46357](https://github.com/pandas-dev/pandas/issues/46357))。
```py
In [6]: df = pd.DataFrame(["a", "b", "c"], dtype="category").iloc[0:2]
In [7]: df
Out[7]:
0
0 a
1 b
旧行为
In [8]: df.groupby(level=0, observed=True).value_counts()
Out[8]:
0 a 1
1 b 1
dtype: int64
新行为
In [9]: df.groupby(level=0, observed=True).value_counts()
Out[9]:
0 a 1
1 a 0
b 1
0 b 0
c 0
1 c 0
dtype: int64
``` ## 不兼容的 API 更改
### 增加了依赖项的最低版本
更新了一些依赖项的最低支持版本。如果已安装,现在我们要求:
| 包 | 最低版本 | 需要 | 已更改 |
| --- | --- | --- | --- |
| numpy | 1.20.3 | X | X |
| mypy (dev) | 0.971 | | X |
| beautifulsoup4 | 4.9.3 | | X |
| blosc | 1.21.0 | | X |
| bottleneck | 1.3.2 | | X |
| fsspec | 2021.07.0 | | X |
| hypothesis | 6.13.0 | | X |
| gcsfs | 2021.07.0 | | X |
| jinja2 | 3.0.0 | | X |
| lxml | 4.6.3 | | X |
| numba | 0.53.1 | | X |
| numexpr | 2.7.3 | | X |
| openpyxl | 3.0.7 | | X |
| pandas-gbq | 0.15.0 | | X |
| psycopg2 | 2.8.6 | | X |
| pymysql | 1.0.2 | | X |
| pyreadstat | 1.1.2 | | X |
| pyxlsb | 1.0.8 | | X |
| s3fs | 2021.08.0 | | X |
| scipy | 1.7.1 | | X |
| sqlalchemy | 1.4.16 | | X |
| tabulate | 0.8.9 | | X |
| xarray | 0.19.0 | | X |
| xlsxwriter | 1.4.3 | | X |
对于[可选库](https://pandas.pydata.org/docs/getting_started/install.html),一般建议使用最新版本。以下表格列出了在 pandas 开发过程中当前正在测试的每个库的最低版本。低于最低测试版本的可选库可能仍然有效,但不被视为受支持。
| 包 | 最低版本 | 已更改 |
| --- | --- | --- |
| beautifulsoup4 | 4.9.3 | X |
| blosc | 1.21.0 | X |
| bottleneck | 1.3.2 | X |
| brotlipy | 0.7.0 | |
| fastparquet | 0.4.0 | |
| fsspec | 2021.08.0 | X |
| html5lib | 1.1 | |
| hypothesis | 6.13.0 | X |
| gcsfs | 2021.08.0 | X |
| jinja2 | 3.0.0 | X |
| lxml | 4.6.3 | X |
| matplotlib | 3.3.2 | |
| numba | 0.53.1 | X |
| numexpr | 2.7.3 | X |
| odfpy | 1.4.1 | |
| openpyxl | 3.0.7 | X |
| pandas-gbq | 0.15.0 | X |
| psycopg2 | 2.8.6 | X |
| pyarrow | 1.0.1 | |
| pymysql | 1.0.2 | X |
| pyreadstat | 1.1.2 | X |
| pytables | 3.6.1 | |
| python-snappy | 0.6.0 | |
| pyxlsb | 1.0.8 | X |
| s3fs | 2021.08.0 | X |
| scipy | 1.7.1 | X |
| sqlalchemy | 1.4.16 | X |
| tabulate | 0.8.9 | X |
| tzdata | 2022a | |
| xarray | 0.19.0 | X |
| xlrd | 2.0.1 | |
| xlsxwriter | 1.4.3 | X |
| xlwt | 1.3.0 | |
| zstandard | 0.15.2 | |
查看依赖项和可选依赖项获取更多信息。 ### 其他 API 更改
+ BigQuery I/O 方法`read_gbq()`和`DataFrame.to_gbq()`默认为`auth_local_webserver = True`。Google 已弃用`auth_local_webserver = False`的[“out of band”(复制粘贴)流程](https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html?m=1#disallowed-oob)。`auth_local_webserver = False`选项计划在 2022 年 10 月停止工作。([GH 46312](https://github.com/pandas-dev/pandas/issues/46312))
+ 当`read_json()`读取的输入是以`.json`、`.json.gz`、`.json.bz2`等结尾的字符串,但文件不存在时,现在会引发`FileNotFoundError`(之前是`ValueError`)([GH 29102](https://github.com/pandas-dev/pandas/issues/29102))
+ 使用`Timestamp`或`Timedelta`进行操作,之前可能会引发`OverflowError`,现在会在适当的情况下引发`OutOfBoundsDatetime`或`OutOfBoundsTimedelta`([GH 47268](https://github.com/pandas-dev/pandas/issues/47268))
+ 当`read_sas()`之前返回`None`时,现在会返回一个空的`DataFrame`([GH 47410](https://github.com/pandas-dev/pandas/issues/47410))
+ `DataFrame`构造函数如果`index`或`columns`参数是集合,则会引发异常([GH 47215](https://github.com/pandas-dev/pandas/issues/47215)) ## 弃用
警告
在下一个主要版本发布 2.0 中,正在考虑进行几项较大的 API 更改,而没有正式弃用,例如将标准库[zoneinfo](https://docs.python.org/3/library/zoneinfo.html)作为默认时区实现,而不是`pytz`,使`Index`支持所有数据类型,而不是有多个子类(`CategoricalIndex`,`Int64Index`等),等等。正在考虑的更改记录在[此 GitHub 问题](https://github.com/pandas-dev/pandas/issues/44823)中,欢迎任何反馈或关注。
### 基于标签的整数切片在具有 Int64Index 或 RangeIndex 的 Series 上
在将来的版本中,对具有`Int64Index`或`RangeIndex`的`Series`进行整数切片将被视为*基于标签*,而不是位置。这将使行为与其他`Series.__getitem__()`和`Series.__setitem__()`的行为保持一致([GH 45162](https://github.com/pandas-dev/pandas/issues/45162))。
例如:
```py
In [29]: ser = pd.Series([1, 2, 3, 4, 5], index=[2, 3, 5, 7, 11])
在旧行为中,ser[2:4]将切片视为位置:
旧行为:
In [3]: ser[2:4]
Out[3]:
5 3
7 4
dtype: int64
在将来的版本中,这将被视为基于标签:
未来行为:
In [4]: ser.loc[2:4]
Out[4]:
2 1
3 2
dtype: int64
要保留旧行为,请使用series.iloc[i:j]。要获得未来行为,请使用series.loc[i:j]。
对DataFrame进行切片不会受影响。### ExcelWriter属性
以前,ExcelWriter的所有属性都被记录为非公开。然而,一些第三方 Excel 引擎记录了访问ExcelWriter.book或ExcelWriter.sheets,用户正在使用这些属性,可能还有其他属性。以前这些属性是不安全的使用;例如,对ExcelWriter.book的修改不会更新ExcelWriter.sheets,反之亦然。为了支持这一点,pandas 已经将一些属性公开,并改进了它们的实现,以便现在可以安全地使用它们。(GH 45572)
以下属性现在是公开的,并被认为是安全访问的。
bookcheck_extensionclosedate_formatdatetime_formatengineif_sheet_existssheetssupported_extensions
以下属性已被弃用。当访问时现在会引发FutureWarning,并将在将来的版本中删除。用户应该意识到它们的使用被认为是不安全的,并可能导致意外结果。
cur_sheethandlespathsavewrite_cells
有关更多详细信息,请参阅ExcelWriter的文档。### 在DataFrameGroupBy.apply()和SeriesGroupBy.apply()中使用group_keys��转换器
在 pandas 的旧版本中,如果推断出传递给DataFrameGroupBy.apply()或SeriesGroupBy.apply()的函数是一个变换器(即结果索引等于输入索引),则会忽略DataFrame.groupby()和Series.groupby()的group_keys参数,并且不会将组键添加到结果的索引中。将来,当用户指定group_keys=True时,组键将添加到索引中。
由于group_keys=True是DataFrame.groupby()和Series.groupby()的默认值,如果没有为变换器指定group_keys,将会引发FutureWarning。可以通过指定group_keys=False来消除此警告并保留先前的行为。
使用loc和iloc设置值时的就地操作
大多数情况下,使用DataFrame.iloc()设置值会尝试就地修改值,只有在必要时才会回退到插入新数组的操作。有些情况下,这个规则并不适用,例如当使用具有不同 dtype 的数组设置整个列时:
In [30]: df = pd.DataFrame({'price': [11.1, 12.2]}, index=['book1', 'book2'])
In [31]: original_prices = df['price']
In [32]: new_prices = np.array([98, 99])
旧行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, float: 64
此行为已被弃用。在将来的版本中,使用 iloc 设置整个列将尝试就地操作。
未来行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98.0
book2 99.0
Name: price, dtype: float64
In [5]: original_prices
Out[5]:
book1 98.0
book2 99.0
Name: price, dtype: float64
要恢复旧的行为,请直接使用DataFrame.__setitem__():
In [3]: df[df.columns[0]] = new_prices
In [4]: df.iloc[:, 0]
Out[4]
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, dtype: float64
要在df.columns不唯一且想要按索引更改单个列的旧行为,可以使用 pandas 1.5 中新增的DataFrame.isetitem():
In [3]: df_with_duplicated_cols = pd.concat([df, df], axis='columns')
In [3]: df_with_duplicated_cols.isetitem(0, new_prices)
In [4]: df_with_duplicated_cols.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: 0, dtype: float64
numeric_only默认值
在DataFrame、DataFrameGroupBy和Resampler等操作中,如min、sum和idxmax,如果存在numeric_only参数,默认值是不一致的。此外,默认值为None的操作可能导致意外的结果。 (GH 46560)
In [1]: df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
In [2]: # Reading the next line without knowing the contents of df, one would
# expect the result to contain the products for both columns a and b.
df[["a", "b"]].prod()
Out[2]:
a 2
dtype: int64
为了避免这种行为,已弃用指定值numeric_only=None,并将在未来的 pandas 版本中移除。将来,所有带有numeric_only参数的操作将默认为False。用户应该只对可以操作的列调用操作,或者指定numeric_only=True仅对布尔值、整数和浮点数列进行操作。
为了支持过渡到新行为,以下方法已获得numeric_only参数。
-
DataFrame.corr() -
DataFrame.corrwith() -
DataFrame.cov() -
DataFrame.idxmin() -
DataFrame.idxmax() -
DataFrameGroupBy.cummin() -
DataFrameGroupBy.cummax() -
DataFrameGroupBy.idxmin() -
DataFrameGroupBy.idxmax() -
DataFrameGroupBy.var() -
DataFrameGroupBy.std() -
DataFrameGroupBy.sem() -
DataFrameGroupBy.quantile() -
Resampler.mean() -
Resampler.median() -
Resampler.sem() -
Resampler.std() -
Resampler.var() -
DataFrame.rolling()操作 -
DataFrame.expanding()操作 -
DataFrame.ewm()操作 ### 其他弃用项 -
在
DataFrame.to_csv()和Series.to_csv()中弃用关键字line_terminator,改用lineterminator;这是为了与read_csv()和标准库的 ‘csv’ 模块保持一致(GH 9568) -
SparseArray.astype()、Series.astype()和DataFrame.astype()在使用非稀疏dtype时的弃用行为。在将来的版本中,这将转换为非稀疏 dtype 而不是将其包装在SparseDtype中(GH 34457) -
DatetimeIndex.intersection()和DatetimeIndex.symmetric_difference()的弃用行为(union行为已在版本 1.3.0 中弃用)与混合时区;在将来的版本中,两者都将被转换为 UTC 而不是对象 dtype(GH 39328, GH 45357) -
弃用
DataFrame.iteritems()、Series.iteritems()、HDFStore.iteritems(),改用DataFrame.items()、Series.items()、HDFStore.items()(GH 45321) -
废弃了
Series.is_monotonic()和Index.is_monotonic(),改用Series.is_monotonic_increasing()和Index.is_monotonic_increasing()(GH 45422, GH 21335) -
废弃了在将
DatetimeIndex.astype()、TimedeltaIndex.astype()、PeriodIndex.astype()转换为除int64以外的整数 dtype 时的行为。在将来的版本中,这些将转换为精确指定的 dtype(而不总是int64),并在转换溢出时引发异常(GH 45034) -
废弃了 DataFrame 和 Series 的
__array_wrap__方法,改为依赖标准的 numpy ufuncs(GH 45451) -
废弃了将 float-dtype 数据在传递时与时区一起传递给
Series或DatetimeIndex时将其视为壁钟时间的行为(GH 45573) -
废弃了在
timedelta64[ns]dtype 和不兼容填充值时Series.fillna()和DataFrame.fillna()的行为;在将来的版本中,这将转换为一个公共的 dtype(通常为 object)而不是引发异常,与其他 dtypes 的行为相匹配(GH 45746) -
废弃了
infer_freq()中的warn参数(GH 45947) -
废弃了允许在
ExtensionArray.argsort()中使用非关键字参数的行为(GH 46134) -
废弃了在
DataFrame.any()和DataFrame.all()中将所有-boolobject-dtype 列视为布尔型列的行为,使用bool_only=True明确转换为布尔型而不是隐式转换(GH 46188) -
方法
DataFrame.quantile()的废弃行为,属性numeric_only将默认为 False。结果中包括日期时间/时间增量列 (GH 7308)。 -
废弃了
Timedelta.freq和Timedelta.is_populated(GH 46430)。 -
废弃了
Timedelta.delta(GH 46476)。 -
废弃了在
DataFrame.any()和Series.any()中作为位置参数传递参数的方式 (GH 44802)。 -
废弃了对
DataFrame.pivot()和pivot()传递位置参数的方式,除了data外 (GH 30228)。 -
废弃了方法
DataFrame.mad()、Series.mad()和相应的 groupby 方法 (GH 11787)。 -
废弃了在
Index.join()中传递位置参数的方式,除了other外,使用关键字参数而不是位置参数 (GH 46518)。 -
废弃了对
StringMethods.rsplit()和StringMethods.split()传递位置参数的方式,除了pat外,使用关键字参数而不是位置参数 (GH 47423)。 -
废弃了在时区无关的
DatetimeIndex上使用代表时区感知的日期时间的字符串进行索引 (GH 46903, GH 36148)。 -
废弃了在使用非圆整浮点值构造函数时允许
unit="M"或unit="Y"的Timestamp,将参数作为位置参数传递 (GH 47267)。 -
废弃了
display.column_space全局配置选项 (GH 7576)。 -
在
factorize()、Index.factorize()和ExtensionArray.factorize()中,已废弃参数na_sentinel;使用use_na_sentinel=True来使用哨兵-1表示 NaN 值,使用use_na_sentinel=False代替na_sentinel=None来编码 NaN 值(GH 46910)。 -
已废弃当 UDF 返回 DataFrame 时,
DataFrameGroupBy.transform()不对齐结果的行为(GH 45648)。 -
在
to_datetime()中,当分隔的日期无法按照指定的dayfirst参数解析时,发出警告已经明确(GH 46210)。 -
在
to_datetime()中,如果无法解析以指定的dayfirst参数为准的分隔日期,即使是省略了前导零的日期(例如31/1/2001),也会发出警告(GH 47880)。 -
已废弃
Series和Resampler的规约器(例如min、max、sum、mean),当 dtype 为非数值且提供了numeric_only=True时,会引发NotImplementedError;在将来的版本中将引发TypeError(GH 47500)。 -
已废弃当 dtype 为非数值且提供了
numeric_only=True时,Series.rank()返回空结果的情况;在将来的版本中将引发TypeError(GH 47500)。 -
对于
Series.mask()、Series.where()、DataFrame.mask()和DataFrame.where(),已废弃参数errors,因为此方法对此参数无效(GH 47728)。 -
在
Rolling、Expanding和ExponentialMovingWindow操作中弃用了参数*args和**kwargs(GH 47836)。 -
在
Categorical.set_ordered()、Categorical.as_ordered()和Categorical.as_unordered()中弃用了inplace关键字(GH 37643)。 -
在设置分类的类别时,弃用
cat.categories = ['a', 'b', 'c'],改用Categorical.rename_categories()(GH 37643)。 -
在
Series.to_excel()和DataFrame.to_excel()中弃用了未使用的参数encoding和verbose(GH 47912)。 -
在
DataFrame.set_axis()和Series.set_axis()中弃用了inplace关键字,改用obj = obj.set_axis(..., copy=False)代替(GH 48130)。 -
在对由长度为 1 的列表分组的
DataFrameGroupBy或SeriesGroupBy进行迭代时,弃用生成单个元素;改为返回长度为一的元组(GH 42795)。 -
修复了对
MultiIndex.lesort_depth()的弃用警告消息,因为以前的消息引用了MultiIndex.is_lexsorted()(GH 38701)。 -
在
DataFrame.plot()和Series.plot()中弃用了sort_columns参数(GH 47563)。 -
对于除
DataFrame.to_stata()和read_stata()的第一个参数外的所有位置参数,改用关键字参数(GH 48128)。 -
在
read_csv()、read_fwf()、read_table()和read_excel()中,已废弃mangle_dupe_cols参数。该参数从未被实现,将添加一个新的参数来指定重命名模式(GH 47718) -
在
Series.astype()中,不再支持使用dtype='datetime64'或dtype=np.datetime64,请改用“datetime64[ns]”代替(GH 47844) ## 性能改进 -
当其他为
Series时,对于列式(axis=0)Pearson 和 Spearman 相关性,DataFrame.corrwith()的性能有所提升(GH 46174) -
在某些用户定义的 DataFrame -> Series 函数中,
DataFrameGroupBy.transform()和SeriesGroupBy.transform()中有性能提升(GH 45387) -
当子集仅包含一列时,
DataFrame.duplicated()的性能有所提升(GH 45236) -
在
DataFrameGroupBy.diff()和SeriesGroupBy.diff()中性能有所提升(GH 16706) -
在用户定义函数广播值时,
DataFrameGroupBy.transform()和SeriesGroupBy.transform()的性能得到改善(GH 45708)。 -
当只存在单一分组时,用户定义函数在
DataFrameGroupBy.transform()和SeriesGroupBy.transform()中的性能得到改善(GH 44977)。 -
在对非唯一非排序索引进行分组时,
DataFrameGroupBy.apply()和SeriesGroupBy.apply()的性能得到改善(GH 46527)。 -
对
MultiIndex进行基于元组的索引时,DataFrame.loc()和Series.loc()的性能得到改善(GH 45681、GH 46040、GH 46330)。 -
在
ddof不等于一时,DataFrameGroupBy.var()和SeriesGroupBy.var()的性能得到改善(GH 48152)。 -
当索引是
MultiIndex时,DataFrame.to_records()的性能得到改善(GH 47263)。 -
当 MultiIndex 包含 DatetimeIndex、TimedeltaIndex 或 ExtensionDtypes 类型的级别时,
MultiIndex.values的性能有所提升(GH 46288) -
当左侧和/或右侧为空时,
merge()的性能有所提升(GH 45838) -
当左侧和/或右侧为空时,
DataFrame.join()的性能有所提升(GH 46015) -
当目标是
MultiIndex时,DataFrame.reindex()和Series.reindex()的性能有所提升(GH 46235) -
在使用 pyarrow 支持的字符串数组设置值时的性能有所提升(GH 46400)
-
在
factorize()中的性能有所提升(GH 46109) -
对于扩展 dtype 标量,
DataFrame和Series构造函数的性能有所提升(GH 45854) -
当提供
nrows参数时,read_excel()的性能有所提升(GH 32727) -
在应用重复的 CSS 格式时,
Styler.to_excel()的性能有所提升(GH 47371) -
在
MultiIndex.is_monotonic_increasing()中的性能有所提升(GH 47458) -
在
BusinessHour的str和repr中的性能有所提升(GH 44764) -
当使用默认的 strftime 格式之一
"%Y-%m-%d %H:%M:%S"或"%Y-%m-%d %H:%M:%S.%f"进行日期时间数组字符串格式化时,性���有所提升(GH 44764) -
Series.to_sql()和DataFrame.to_sql()函数中的性能改进(SQLiteTable),在处理时间数组时提升性能(GH 44764) -
read_sas()函数的性能改进(GH 47404) -
argmax和argmin函数在arrays.SparseArray中的性能改进(GH 34197) ## Bug 修复
分类
-
Categorical.view()函数中存在的问题,不接受整数数据类型(GH 25464) -
CategoricalIndex.union()函数中存在的问题,当索引的类别为整数数据类型且索引包含NaN值时,错误地引发异常而不是转换为float64数据类型(GH 45362) -
concat()函数中存在的��题,当连接两个(或多个)无序的CategoricalIndex变量,其类别为排列组合时,产生错误的索引值(GH 24845)
日期时间类
-
DataFrame.quantile()函数中存在的问题,当处理类似日期时间的数据类型且没有行时,错误地返回float64数据类型而不是保留日期时间数据类型(GH 41544) -
to_datetime()函数中存在的问题,当处理np.str_对象序列时错误地引发异常(GH 32264) -
Timestamp构造函数中存在的问题,当将日期时间组件作为位置参数传递且将tzinfo作为关键字参数传递时,错误地引发异常(GH 31929) -
Index.astype()函数中存在的问题,当从对象数据类型转换为timedelta64[ns]数据类型时,错误地将np.datetime64("NaT")值转换为np.timedelta64("NaT")而不是引发异常(GH 45722) -
在传递分类列时,
SeriesGroupBy.value_counts()索引存在错误(GH 44324) -
在将时区本地化为 UTC 时,
DatetimeIndex.tz_localize()未能复制基础数据(GH 46460) -
在
DatetimeIndex.resolution()中存在错误,对于纳秒分辨率的索引,错误地返回“day”而不是“nanosecond”(GH 46903) -
在传递整数或浮点值且
unit="Y"或unit="M"时,Timestamp存在错误,结果略有偏差(GH 47266) -
在传递另一个
DatetimeArray和freq=None时,DatetimeArray构造存在错误,错误地从给定数组推断频率(GH 47296) -
在
to_datetime()中存在错误,即使errors=coerce,如果行数超过 50 行,也会抛出OutOfBoundsDatetime错误(GH 45319) -
向
Series添加DateOffset时存在错误,不会添加nanoseconds字段(GH 47856)
时间差
-
在
astype_nansafe()中存在错误,当包含 np.nan 时,astype(“timedelta64[ns]”)会失败(GH 45798) -
通过
np.timedelta64对象和unit构造Timedelta时,有时会悄悄溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta错误(GH 46827) -
从大整数或浮点数构造
Timedelta时,unit="W"会悄悄溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta错误(GH 47268)
时区
- 在传递
ZoneInfotzinfo 对象时,Timestamp构造函数会出错(GH 46425)
数值
-
与
dtype="boolean"和NA一起进行操作时出现错误,错误地改变数组的值(GH 45421) -
在没有
NA值的可空类型的算术操作中,与非可空类型的相同操作不匹配(GH 48223) -
在用
IntegerDtype除以0时,floordiv中的错误返回0而不是inf(GH 48223) -
在
dtype="boolean"的数组上进行除法、pow和mod操作时,与它们的np.bool_对应项不同(GH 46063) -
用
IntegerDtype或FloatingDtype乘以timedelta64[ns]类型的数组时出现错误提升Series(GH 45622) -
在
mean()中,可选依赖bottleneck导致数组长度线性减少。已禁用bottleneck以改善mean()的损失为对数线性,但可能导致性能下降。(GH 42878)
转换
-
DataFrame.astype()中的错误未保留子类(GH 40810) -
从包含浮点数的列表或浮点数 dtype 的类似 ndarray(例如
dask.Array)构建Series时出现错误提升,而不是像np.ndarray一样转换(GH 40110) -
Float64Index.astype()中的错误将无符号整数类型错误地转换为np.int64类型(GH 45309) -
从浮点类型到无符号整数类型时,
Series.astype()和DataFrame.astype()中的错误未在存在负值时提升(GH 45151) -
用
FloatingDtype和包含可转换为浮点数的字符串值的值构建array()时出现错误提升(GH 45424) -
比较字符串和 datetime64ns 对象时出现错误,导致
OverflowError异常。(GH 45506) -
通用抽象 dtype 的元类中的错误,导致内置函数
type引发DataFrame.apply()和Series.apply()(GH 46684) -
DataFrame.to_records()中的错误,如果索引是MultiIndex,则返回不一致的 numpy 类型(GH 47263) -
DataFrame.to_dict()中的错误,对于orient="list"或orient="index",未返回原生类型 (GH 46751) -
DataFrame.apply()中的错误,在应用于空的DataFrame且axis=1时返回一个DataFrame而不是一个Series(GH 39111) -
从非 NumPy
ndarray推断 dtype 时的错误,该数组不是由所有 NumPy 无符号整数标量组成,未导致无符号整数 dtype (GH 47294) -
在列名为 pandas 对象(例如
'Timestamp')时,DataFrame.eval()中的错误 (GH 44603)
字符串
-
使用其他系列作为参数 pat 时,
str.startswith()和str.endswith()中的错误。现在引发TypeError(GH 3485) -
当字符串包含前导符号时,
Series.str.zfill()中的错误,将 ‘0’ 填充在符号字符之前而不是之后,如标准库中的str.zfill(GH 20868)
区间
-
当将
np.nan设置到整数支持的数组中时,IntervalArray.__setitem__()中的错误引发ValueError而不是TypeError(GH 45484) -
使用 datetime64[ns, tz]作为 dtype 字符串时的
IntervalDtype中存在的错误(GH 46999)
索引
-
当使用单个 ExtensionDtype 列的单个行对
DataFrame进行索引时,DataFrame.iloc()中存在的错误,返回的是基础数据的副本而不是视图(GH 45241) -
当
DataFrame具有重复列时,DataFrame.__getitem__()返回副本的错误,即使选择了唯一列(GH 45316,GH 41062) -
Series.align()中存在的错误:当两个多级索引的交集相同时,不会创建多级索引的并集(GH 45224) -
将 NA 值(
None或np.nan)错误地设置为对象 dtype 而不是浮点数 dtype 的基于整数的IntervalDtype的Series中的错误(GH 45568) -
通过
df.iloc[:, i] = values将值设置到ExtensionDtype列中时,values与df.iloc[:, i]具有相同 dtype 时,错误地插入新数组而不是原位设置的错误(GH 33457) -
当使用非整数
Index以整数键设置不能原地设置的值时,Series.__setitem__()中的错误,会引发ValueError,而不是转换为常见 dtype(GH 45070) -
在将值作为列表设置到
DataFrame时,DataFrame.loc()中存在的错误,不会将None转换为NA(GH 47987) -
Series.__setitem__()中的 Bug:将不兼容的值设置到PeriodDtype或IntervalDtypeSeries时,在使用布尔掩码进行索引时引发异常,但在使用其他等效索引器进行索引时进行强制转换;现在这些都会一致强制转换,以及Series.mask()和Series.where()(GH 45768) -
DataFrame.where()中的 Bug:对于具有 datetime 类型的多列,失败的 downcast 结果与其他类型不一致(GH 45837) -
isin()函数中的 Bug:当无符号整数 dtype 和类似列表的参数没有 dtype 时会上转换为float64类型(GH 46485) -
Series.loc.__setitem__()和Series.loc.__getitem__()中的 Bug:在不使用MultiIndex的情况下使用多个键时未引发异常(GH 13831) -
Index.reindex()中的 Bug:当指定了level但未给出MultiIndex时引发AssertionError;现在忽略了 level 参数(GH 35132) -
loc.__setitem__()中的 Bug:将range键视为位置而不是基于标签的键(GH 45479) -
DataFrame.__setitem__()中的 Bug:当使用标量键和DataFrame作为值进行设置时,将扩展数组 dtype 转换为对象(GH 46896) -
Series.__setitem__()中的 Bug:当将标量设置为可空 pandas dtype 时,如果标量无法无损转换为可空类型,则不会引发TypeError(GH 45404) -
Series.__setitem__()中的 Bug:设置包含NA的boolean类型值时,错误地引发而不是转换为boolean类型(GH 45462) -
Series.loc()中的 Bug 在包含NA的布尔索引器引发错误时,当Index不匹配时(GH 46551) -
Series.__setitem__()中的 Bug 导致将NA设置为数值类型Series时,错误地将其上转为对象类型,而不是将值视为np.nan(GH 44199) -
DataFrame.loc()中的 Bug 在将值设置为列且右侧是字典时出现问题(GH 47216) -
Series.__setitem__()中的 Bug 在具有datetime64[ns]dtype、全为False的布尔掩码和不兼容值时,错误地转换为object而不是保留datetime64[ns]dtype(GH 45967) -
Index.__getitem__()中的 Bug 在索引器来自布尔类型且具有NA时引发ValueError(GH 45806) -
Series.__setitem__()中的 Bug 在扩大带有标量的Series时丢失精度(GH 32346) -
Series.mask()中的 Bug 在inplace=True或使用小整数类型的布尔掩码设置值时错误地引发异常(GH 45750) -
DataFrame.mask()中的 Bug 在inplace=True和ExtensionDtype列中错误地引发异常(GH 45577) -
从具有类似日期时间值的对象类型行索引的 DataFrame 获取列时出现 Bug:结果 Series 现在保留了来自父 DataFrame 的确切对象类型索引(GH 42950)
-
DataFrame.__getattribute__()中的 Bug 导致如果列具有"string"dtype,则引发AttributeError(GH 46185) -
DataFrame.compare()中的 Bug 在比较扩展数组 dtype 和 numpy dtype 时返回所有NaN列(GH 44014) -
DataFrame.where()中的 Bug 在为 numpy dtype 设置错误的值时,使用"boolean"掩码(GH 44014) -
在
DatetimeIndex上进行索引时,使用np.str_键会错误地引发异常(GH 45580) -
在
CategoricalIndex.get_indexer()中的错误,当索引包含NaN值时,导致目标中存在但不在索引中的元素被映射到 NaN 元素的索引位置,而不是-1 (GH 45361) -
将大整数值设置到带有
float32或float16dtype 的Series中的错误,会错误地改变这些值,而不是强制转换为float64dtype (GH 45844) -
Series.asof()和DataFrame.asof()中的错误会将 bool 型结果错误地转换为float64类型(GH 16063) -
NDFrame.xs()、DataFrame.iterrows()、DataFrame.loc()和DataFrame.iloc()中的错误,不总是传播元数据 (GH 28283) -
DataFrame.sum()中的错误,如果输入包含 NaN 值,则 min_count 会更改 dtype (GH 46947) -
IntervalTree中的错误导致无限递归。(GH 46658) -
在
PeriodIndex上进行索引时,当索引为NA时引发AttributeError,而不是将NaT放在其位置。(GH 46673) -
DataFrame.at()中的错误会允许修改多列(GH 48296)
缺失
-
Series.fillna()和DataFrame.fillna()中downcast关键字在某些情况下未被尊重,即使没有 NA 值存在(GH 45423) -
Bug in
Series.fillna()和DataFrame.fillna()在使用IntervalDtype和不兼容值时引发错误,而不是转换为通用(通常是对象)dtype(GH 45796) -
Bug in
Series.map()如果映射器是dict或Series,则不遵守na_action参数(GH 47527) -
Bug in
DataFrame.interpolate()在对象类型列上使用inplace=False时未返回副本(GH 45791) -
Bug in
DataFrame.dropna()允许设置不兼容的how和thresh参数(GH 46575) -
Bug in
DataFrame.fillna()当DataFrame为单个块时忽略了axis(GH 47713)
MultiIndex
-
Bug in
DataFrame.loc()在使用负步长和非空起始/结束值切片MultiIndex时返回空结果(GH 46156) -
Bug in
DataFrame.loc()在使用负步长切片MultiIndex时引发错误(GH 46156) -
Bug in
DataFrame.loc()在使用负步长切片和切片非整数标签索引级别时引发错误(GH 46156) -
Bug in
Series.to_numpy()在提供na_value时,多级索引的 Series 无法转换为 numpy 数组(GH 45774) -
MultiIndex.equals中的错误,在只有一侧具有扩展数组数据类型时不是可交换的(GH 46026) -
Bug in
MultiIndex.from_tuples()无法构建空元组的索引(GH 45608)
I/O
-
Bug in
DataFrame.to_stata()如果DataFrame包含-np.inf,则不会引发错误(GH 45350) -
Bug in
read_excel()在某些skiprows可调用情况下导致无限循环(GH 45585) -
Bug in
DataFrame.info()在空的DataFrame上调用时,输出末尾的换行符被省略了(GH 45494) -
Bug in
read_csv()在engine="c"的情况下,对on_bad_lines="warn"的换行符无法识别(GH 41710) -
Bug in
DataFrame.to_csv()在Float64数据类型的情况下不尊重float_format(GH 45991) -
Bug in
read_csv()在某些情况下不尊重指定的索引列转换器(GH 40589) -
Bug in
read_csv()即使index_col=False,也会将第二行解释为Index名称(GH 46569) -
Bug in
read_parquet()当engine="pyarrow"时,如果传递了不支持的数据类型列,会导致部分写入磁盘(GH 44914) -
当向
.ods文件写入空 DataFrame 时,DataFrame.to_excel()和ExcelWriter会出错(GH 45793) -
当
engine="python"时,read_csv()忽略不存在的标题行(GH 47400) -
当
header引用不存在的行时,read_excel()抛出未受控制的IndexError(GH 43143) -
read_html()中存在错误,围绕<br>的元素在它们之间没有空格地连接起来(GH 29528) -
当数据长度超过标题行时,
read_csv()存在错误,导致在usecols中期待字符串的可调用函数出现问题(GH 46997) -
Parquet roundtrip 中存在错误,对于带有
datetime64[ns]子类型的 Interval dtype (GH 45881) -
在读取
.ods文件时,read_excel()存在错误,xml 元素之间存在换行符(GH 45598) -
当
engine="fastparquet"时,read_parquet()存在错误,文件在错误时未关闭(GH 46555) -
DataFrame.to_html()现在在border关键字设置为False时从<table>元素中排除border属性。 -
read_sas()在某些类型的压缩 SAS7BDAT 文件中存在错误(GH 35545) -
在未提供名称时,
read_excel()在没有给定名称时未向前填充MultiIndex(GH 47487) -
当 SAS7BDAT 文件行数为零时,
read_sas()返回None而不是空 DataFrame(GH 18198) -
在
DataFrame.to_string()中存在错误的 bug,使用扩展数组时缺失值错误地使用了MultiIndex(GH 47986) -
在
StataWriter中存在 bug,值标签始终以默认编码写入 (GH 46750) -
在
StataWriterUTF8中存在 bug,其中一些有效字符从变量名中被删除 (GH 47276) -
当使用
MultiIndex写入空数据框时,在DataFrame.to_excel()中存在 bug (GH 19543) -
在包含 0x40 控制字节的 RLE 压缩的 SAS7BDAT 文件中,存在 bug 在
read_sas()中,导致了错误的结果 (GH 31243) -
在
read_sas()中存在 bug,混淆了列名 (GH 31243) -
在包含 0x00 控制字节的 RLE 压缩的 SAS7BDAT 文件中,存在 bug 在
read_sas()中,导致了错误的结果 (GH 47099) -
当
use_nullable_dtypes=True时,在read_parquet()中存在 bug,返回float64dtype 而不是可空的Float64dtype (GH 45694) -
在
DataFrame.to_json()中存在 bug,PeriodDtype在使用read_json()读回时不能进行序列化往返 (GH 44720) -
在读取带有中文字符标签的 XML 文件时,在
read_xml()中存在 bug,会引发XMLSyntaxError(GH 47902)
周期
-
在从
PeriodArray减去Period时返回错误结果 (GH 45999) -
Period.strftime()和PeriodIndex.strftime()中,指令%l和%u提供的结果不正确(GH 46252) -
传递字符串给
Period微秒是 1000 的倍数时,推断出不正确的freq中的错误(GH 46811) -
从具有非零纳秒和
freq="ns"的Timestamp或np.datetime64对象构造Period时,错误地截断了纳秒(GH 46811) -
将
np.timedelta64("NaT", "ns")添加到具有类似时间间隔的freq的Period时,错误地引发了IncompatibleFrequency,而不是返回NaT(GH 47196) -
向具有
PeriodDtype的数组添加整数数组时,当dtype.freq.n > 1时,结果不正确(GH 47209) -
从具有
PeriodDtype的数组中减去Period时,返回的结果不正确,而不是在操作溢出时引发OverflowError(GH 47538)
绘图
-
DataFrame.plot.barh()中的错误导致无法标记 x 轴和xlabel更新 y 轴标签(GH 45144) -
DataFrame.plot.box()中的错误导致无法标记 x 轴(GH 45463) -
DataFrame.boxplot()中的错误导致无法传递xlabel和ylabel(GH 45463) -
DataFrame.boxplot()中的错误导致无法指定vert=False(GH 36918) -
DataFrame.plot.scatter()中的错误导致无法指定norm(GH 45809) -
修复了在
Series.plot()中未设置 ylabel 时显示“None”的问题(GH 46129) -
DataFrame.plot()中的错误导致在绘制季度系列时,xticks 和垂直网格线被错误放置(GH 47602) -
DataFrame.plot()中的错误导致无法为次要 y 轴设置 y 轴标签、限制和刻度(GH 47753)
Groupby/resample/rolling
-
DataFrame.resample()中的错误忽略了在TimedeltaIndex上设置closed="right"(GH 45414) -
DataFrameGroupBy.transform()中的错误在于当func="size"且输入的 DataFrame 有多列时会失败(GH 27469) -
DataFrameGroupBy.size()和DataFrameGroupBy.transform()中的错误在于当func="size"时,axis=1时会产生不正确的结果(GH 45715) -
在
ExponentialMovingWindow.mean()中的错误,当axis=1且engine='numba'时,当DataFrame的列数多于行数时(GH 46086) -
当使用
engine="numba"时,修改engine_kwargs会返回相同的 jitted 函数的错误(GH 46086) -
修复了当
axis=1且func为"first"或"last"时DataFrameGroupBy.transform()失败的问题 (GH 45986) -
修复了
DataFrameGroupBy.cumsum()中skipna=False导致的错误结果 (GH 46216) -
修复了
DataFrameGroupBy.sum()、SeriesGroupBy.sum()、DataFrameGroupBy.prod()、SeriesGroupBy.prod, :meth:().DataFrameGroupBy.cumsum和SeriesGroupBy.cumsum()` 中整数类型丢失精度的问题 (GH 37493) -
修复了
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()中timedelta64[ns]类型无法识别NaT为 null 值的问题 (GH 46216) -
修复了
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()在整数类型导致的溢出问题,当和大于类型的最大值时 (GH 37493) -
DataFrameGroupBy.cummin()、SeriesGroupBy.cummin()、DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()中的错误,具有可空数据类型的数据不正确地在原始数据中进行更改(GH 46220) -
DataFrame.groupby()中的错误,在MultiIndex的第一级中出现None时引发错误(GH 47348) -
DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()中的错误,int64类型的数据,且最小可能的 int64 值为首个值时(GH 46382) -
DataFrameGroupBy.cumprod()和SeriesGroupBy.cumprod()中的错误,NaN对skipna=False情况下不同列的计算产生影响(GH 48064) -
DataFrameGroupBy.max()和SeriesGroupBy.max()中的错误,空组和uint64类型的数据不正确地引发RuntimeError(GH 46408) -
DataFrameGroupBy.apply()和SeriesGroupBy.apply()中的 Bug 会在func是字符串且提供了 args 或 kwargs 时失败(GH 46479) -
SeriesGroupBy.apply()中的 Bug 会在存在唯一分组时错误地命名其结果(GH 46369) -
Rolling.sum()和Rolling.mean()中的 Bug 会在窗口中存在相同值时给出错误的结果(GH 42064,GH 46431) -
Rolling.var()和Rolling.std()中的 Bug 会在窗口中存在相同值时给出非零结果(GH 42064) -
Rolling.skew()和Rolling.kurt()中的 Bug 会在窗口中存在相同值时返回 NaN(GH 30993) -
Rolling.var()中的 Bug 会在窗口大小大于数据大小时计算加权方差时导致段错误(GH 46760) -
Grouper.__repr__()中的 Bug 中未包含dropna。现在已经包含(GH 46754) -
DataFrame.rolling()中的 Bug 会在 center=True,axis=1 且指定了 win_type 时引发 ValueError(GH 46135) -
DataFrameGroupBy.describe()和SeriesGroupBy.describe()在空数据集上产生不一致的结果(GH 41575) -
当与
on一起使用时,DataFrame.resample()的缩减方法存在错误,它会尝试对提供的列进行聚合(GH 47079) -
当输入 DataFrame/Series 中的
MultiIndex包含 NaN 值时,DataFrame.groupby()和Series.groupby()不会尊重dropna=False(GH 46783) -
当从一个缺少重采样键的键列表中获取结果时,
DataFrameGroupBy.resample()存在一个错误,会引发KeyError(GH 47362) -
当 DataFrame 为空时,
DataFrame.groupby()存在一个错误,会丢失索引列,例如在进行转换时,比如 fillna(GH 47787) -
当输入 DataFrame/Series 中的 NaN 值时,
DataFrame.groupby()和Series.groupby()与dropna=False和sort=False一起使用时,将任何空组放在最后而不是它们遇到的顺序中(GH 46584)
重塑
-
在一个具有整数数据类型的
Series和另一个具有整数类别和包含NaN值的CategoricalDtype之间的concat()存在一个错误,会将其转换为对象数据类型而不是float64(GH 45359) -
get_dummies()存在一个错误,它选择了对象和类别数据类型,但没有选择字符串(GH 44965) -
在
DataFrame.align()函数中的一个错误,当将MultiIndex对齐到另一个带有MultiIndex的Series时会引发错误(GH 46001) -
在与
IntegerDtype或FloatingDtype数组连接时,导致结果 dtype 不反映非空 dtypes 的行为的错误(GH 46379) -
在
concat()函数中的一个错误,当join="outer"且sort=True时会丢失列的 dtype(GH 47329) -
在
concat()函数中的一个错误,当包含None时不会对列名进行排序(GH 47331) -
在
concat()函数中的一个错误,当索引相同的键导致索引MultiIndex时会引发错误(GH 46519) -
在
pivot_table()函数中的一个错误,当dropna=True且聚合列具有扩展数组类型时会引发TypeError错误(GH 47477) -
在
merge()函数中的一个错误,当在 ssl 库中使用FIPS模式时,使用how="cross"会引发错误(GH 48024) -
在
DataFrame.join()函数中的一个错误,当使用后缀连接具有重复列名的 DataFrame 列表时会引发错误(GH 46396) -
在
DataFrame.pivot_table()函数中的一个错误,当sort=False时结果会导致索引排序(GH 17041) -
在
concat()函数中的一个错误,当axis=1且sort=False时,结果索引为Int64Index而不是RangeIndex(GH 46675) -
在
wide_to_long()函数中的一个错误,当stubnames在列中缺失且i包含字符串类型列时会引发错误(GH 46044) -
在具有分类索引的
DataFrame.join()中出现 Bug 导致意外重新排序(GH 47812)
Sparse
-
在
Series.where()和DataFrame.where()中出现 Bug,使用SparseDtype未能保留数组的fill_value(GH 45691) -
SparseArray.unique()中的 Bug 未能保持原始元素顺序(GH 47809)
ExtensionArray
- 在
IntegerArray.searchsorted()和FloatingArray.searchsorted()中出现 Bug,当作用于np.nan时返回不一致的结果(GH 45255)
Styler
-
尝试将样式函数应用于空 DataFrame 子集时出现 Bug(GH 45313)
-
在
CSSToExcelConverter中出现 Bug,当为xlsxwriter引擎提供边框颜色但未提供边框样式时导致TypeError(GH 42276) -
在暗模式下,Bug 在
Styler.set_sticky()中导致白色文本显示在白色背景上(GH 46984) -
在
Styler.to_latex()中出现 Bug,当clines="all;data"且DataFrame没有行时导致UnboundLocalError(GH 47203) -
当使用
xlsxwriter引擎时,Bug 在Styler.to_excel()中使用vertical-align: middle;时导致问题(GH 30107) -
在具有布尔列标签的 DataFrame 上应用样式时出现 Bug(GH 47838)
元数据
其他
- 在
assert_index_equal()中出现 Bug,当names=True且check_order=False时未检查名称([GH 47328](https://github.com/pandas-dev/pandas/issues/47328)## 贡献者
总共有 271 人为此版本贡献了补丁。名字后带有“+”的人第一次为此贡献了补丁。
-
Aadharsh Acharya +
-
Aadharsh-Acharya +
-
Aadhi Manivannan +
-
Adam Bowden
-
Aditya Agarwal +
-
Ahmed Ibrahim +
-
Alastair Porter +
-
Alex Povel +
-
Alex-Blade
-
Alexandra Sciocchetti +
-
AlonMenczer +
-
Andras Deak +
-
Andrew Hawyrluk
-
Andy Grigg +
-
Aneta Kahleová +
-
Anthony Givans +
-
Anton Shevtsov +
-
B. J. Potter +
-
BarkotBeyene +
-
Ben Beasley +
-
Ben Wozniak +
-
Bernhard Wagner +
-
Boris Rumyantsev
-
Brian Gollop +
-
CCXXXI +
-
Chandrasekaran Anirudh Bhardwaj +
-
Charles Blackmon-Luca +
-
Chris Moradi +
-
ChrisAlbertsen +
-
Compro Prasad +
-
DaPy15
-
Damian Barabonkov +
-
Daniel I +
-
Daniel Isaac +
-
Daniel Schmidt
-
Danil Iashchenko +
-
Dare Adewumi
-
Dennis Chukwunta +
-
Dennis J. Gray +
-
Derek Sharp +
-
Dhruv Samdani +
-
Dimitra Karadima +
-
Dmitry Savostyanov +
-
Dmytro Litvinov +
-
Do Young Kim +
-
Dries Schaumont +
-
Edward Huang +
-
Eirik +
-
Ekaterina +
-
Eli Dourado +
-
Ezra Brauner +
-
Fabian Gabel +
-
FactorizeD +
-
Fangchen Li
-
Francesco Romandini +
-
Greg Gandenberger +
-
Guo Ci +
-
Hiroaki Ogasawara
-
Hood Chatham +
-
Ian Alexander Joiner +
-
Irv Lustig
-
Ivan Ng +
-
JHM Darbyshire
-
JHM Darbyshire (MBP)
-
JHM Darbyshire (iMac)
-
JMBurley
-
Jack Goldsmith +
-
James Freeman +
-
James Lamb
-
James Moro +
-
Janosh Riebesell
-
Jarrod Millman
-
Jason Jia +
-
Jeff Reback
-
Jeremy Tuloup +
-
Johannes Mueller
-
John Bencina +
-
John Mantios +
-
John Zangwill
-
Jon Bramley +
-
Jonas Haag
-
Jordan Hicks
-
Joris Van den Bossche
-
Jose Ortiz +
-
JosephParampathu +
-
José Duarte
-
Julian Steger +
-
Kai Priester +
-
Kapil E. Iyer +
-
Karthik Velayutham +
-
Kashif Khan
-
Kazuki Igeta +
-
Kevin Jan Anker +
-
Kevin Sheppard
-
Khor Chean Wei
-
Kian Eliasi
-
Kian S +
-
Kim, KwonHyun +
-
Kinza-Raza +
-
Konjeti Maruthi +
-
Leonardus Chen
-
Linxiao Francis Cong +
-
Loïc Estève
-
LucasG0 +
-
Lucy Jiménez +
-
Luis Pinto
-
Luke Manley
-
Marc Garcia
-
Marco Edward Gorelli
-
Marco Gorelli
-
MarcoGorelli
-
Margarete Dippel +
-
Mariam-ke +
-
Martin Fleischmann
-
Marvin John Walter +
-
Marvin Walter +
-
Mateusz
-
Matilda M +
-
Matthew Roeschke
-
Matthias Bussonnier
-
MeeseeksMachine
-
Mehgarg +
-
Melissa Weber Mendonça +
-
Michael Milton +
-
Michael Wang
-
Mike McCarty +
-
Miloni Atal +
-
Mitlasóczki Bence +
-
Moritz Schreiber +
-
Morten Canth Hels +
-
Nick Crews +
-
NickFillot +
-
Nicolas Hug +
-
Nima Sarang
-
Noa Tamir +
-
Pandas Development Team
-
Parfait Gasana
-
Parthi +
-
Partho +
-
Patrick Hoefler
-
Peter
-
Peter Hawkins +
-
Philipp A
-
Philipp Schaefer +
-
Pierrot +
-
Pratik Patel +
-
Prithvijit
-
Purna Chandra Mansingh +
-
Radoslaw Lemiec +
-
RaphSku +
-
Reinert Huseby Karlsen +
-
Richard Shadrach
-
Richard Shadrach +
-
Robbie Palmer
-
Robert de Vries
-
Roger +
-
Roger Murray +
-
Ruizhe Deng +
-
SELEE +
-
Sachin Yadav +
-
Saiwing Yeung +
-
Sam Rao +
-
Sandro Casagrande +
-
Sebastiaan Vermeulen +
-
Shaghayegh +
-
Shantanu +
-
Shashank Shet +
-
Shawn Zhong +
-
Shuangchi He +
-
Simon Hawkins
-
Simon Knott +
-
Solomon Song +
-
Somtochi Umeh +
-
Stefan Krawczyk +
-
Stefanie Molin
-
Steffen Rehberg
-
Steven Bamford +
-
Steven Rotondo +
-
Steven Schaerer
-
Sylvain MARIE +
-
Sylvain Marié
-
Tarun Raghunandan Kaushik +
-
Taylor Packard +
-
Terji Petersen
-
Thierry Moisan
-
Thomas Grainger
-
Thomas Hunter +
-
Thomas Li
-
Tim McFarland +
-
Tim Swast
-
Tim Yang +
-
Tobias Pitters
-
Tom Aarsen +
-
Tom Augspurger
-
Torsten Wörtwein
-
TraverseTowner +
-
Tyler Reddy
-
Valentin Iovene
-
Varun Sharma +
-
Vasily Litvinov
-
Venaturum
-
Vinicius Akira Imaizumi +
-
Vladimir Fokow +
-
Wenjun Si
-
Will Lachance +
-
William Andrea
-
Wolfgang F. Riedl +
-
Xingrong Chen
-
Yago González
-
Yikun Jiang +
-
Yuanhao Geng
-
Yuval +
-
Zero
-
郑飞 王 +
-
abmyii
-
alexondor +
-
alm
-
andjhall +
-
anilbey +
-
arnaudlegout +
-
asv-bot +
-
ateki +
-
auderson +
-
bherwerth +
-
bicarlsen +
-
carbonleakage +
-
charles +
-
charlogazzo +
-
code-review-doctor +
-
dataxerik +
-
deponovo
-
dimitra-karadima +
-
dospix +
-
ehallam +
-
ehsan shirvanian +
-
ember91 +
-
eshirvana
-
fractionalhare +
-
gaotian98 +
-
gesoos
-
github-actions[bot]
-
gunghub +
-
hasan-yaman
-
iansheng +
-
iasoon +
-
jbrockmendel
-
joshuabello2550 +
-
jyuv +
-
kouya takahashi +
-
mariana-LJ +
-
matt +
-
mattB1989 +
-
nealxm +
-
partev
-
poloso +
-
realead
-
roib20 +
-
rtpsw
-
ryangilmour +
-
shourya5 +
-
srotondo +
-
stanleycai95 +
-
staticdev +
-
tehunter +
-
theidexisted +
-
tobias.pitters +
-
uncjackg +
-
vernetya
-
wany-oh +
-
wfr +
-
z3c0 + ## 增强
pandas-stubs
pandas-stubs 库现在由 pandas 开发团队支持,为 pandas API 提供类型存根。请访问 pandas-dev/pandas-stubs 获取更多信息。
我们感谢 VirtusLab 和 Microsoft 对 pandas-stubs 的初期重要贡献 ### 原生 PyArrow 支持的 ExtensionArray
使用 Pyarrow 安装后,用户现在可以创建由 pyarrow.ChunkedArray 和 pyarrow.DataType 支持的 pandas 对象。
dtype 参数可以接受带有 pyarrow 方括号的 pyarrow 数据类型 字符串,例如 "int64[pyarrow]",或者对于接受参数的 pyarrow 数据类型,可以使用 ArrowDtype 初始化一个 pyarrow.DataType。
In [1]: import pyarrow as pa
In [2]: ser_float = pd.Series([1.0, 2.0, None], dtype="float32[pyarrow]")
In [3]: ser_float
Out[3]:
0 1.0
1 2.0
2 <NA>
dtype: float[pyarrow]
In [4]: list_of_int_type = pd.ArrowDtype(pa.list_(pa.int64()))
In [5]: ser_list = pd.Series([[1, 2], [3, None]], dtype=list_of_int_type)
In [6]: ser_list
Out[6]:
0 [1\. 2.]
1 [ 3\. nan]
dtype: list<item: int64>[pyarrow]
In [7]: ser_list.take([1, 0])
Out[7]:
1 [ 3\. nan]
0 [1\. 2.]
dtype: list<item: int64>[pyarrow]
In [8]: ser_float * 5
Out[8]:
0 5.0
1 10.0
2 <NA>
dtype: float[pyarrow]
In [9]: ser_float.mean()
Out[9]: 1.5
In [10]: ser_float.dropna()
Out[10]:
0 1.0
1 2.0
dtype: float[pyarrow]
大多数操作都得到支持,并且已经使用 pyarrow compute 函数实现。我们建议安装最新版本的 PyArrow 以访问最新实现的计算函数。
警告
此功能属于实验性质,API 可能在未来的发布中更改,恕不另行通知 ### DataFrame 交换协议实现
Pandas 现在实现了 DataFrame 交换 API 规范。查看 API 的完整详情请访问 data-apis.org/dataframe-protocol/latest/index.html
该协议由两部分组成:
-
新方法
DataFrame.__dataframe__()可以生成交换对象。它有效地“导出” pandas 数据框作为交换对象,因此任何其他实现了该协议的库都可以“导入”该数据框,而无需知道生产者的任何信息,除了它生成了一个交换对象。 -
新函数
pandas.api.interchange.from_dataframe()可以从任何符合规范的库中获取任意交换对象,并构建一个 pandas DataFrame。 ### Styler
最显著的发展是新方法Styler.concat(),它允许添加自定义的页脚行来可视化数据上的额外计算,例如总计和计数等。(GH 43875, GH 46186)
此外,还有一种替代输出方法Styler.to_string(),允许使用 Styler 的格式化方法创建,例如,CSV 文件(GH 44502)。
还提供了一个新功能Styler.relabel_index(),用于提供对索引或列标题的完全自定义显示(GH 47864)
小功能改进包括:
参数group_keys已添加到方法DataFrame.resample()中。与DataFrame.groupby()一样,此参数控制了在使用Resampler.apply()时是否将每个组添加到重新采样中的索引中。
警告
不指定 group_keys 参数将保留先前的行为,并且如果通过指定 group_keys=False 结果会发生变化,则会发出警告。 在 pandas 的将来版本中,不指定 group_keys 将默认为与 group_keys=False 相同的行为。
In [11]: df = pd.DataFrame(
....: {'a': range(6)},
....: index=pd.date_range("2021-01-01", periods=6, freq="8H")
....: )
....:
In [12]: df.resample("D", group_keys=True).apply(lambda x: x)
Out[12]:
a
2021-01-01 2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [13]: df.resample("D", group_keys=False).apply(lambda x: x)
Out[13]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
以前,结果索引取决于 apply 返回的值,如下例所示。
In [1]: # pandas 1.3
In [2]: df.resample("D").apply(lambda x: x)
Out[2]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [3]: df.resample("D").apply(lambda x: x.reset_index())
Out[3]:
index a
2021-01-01 0 2021-01-01 00:00:00 0
1 2021-01-01 08:00:00 1
2 2021-01-01 16:00:00 2
2021-01-02 0 2021-01-02 00:00:00 3
1 2021-01-02 08:00:00 4
2 2021-01-02 16:00:00 5
``` ### from_dummies
新增了新函数 `from_dummies()`,用于将虚拟编码的 `DataFrame` 转换为分类的 `DataFrame`。
```py
In [11]: import pandas as pd
In [12]: df = pd.DataFrame({"col1_a": [1, 0, 1], "col1_b": [0, 1, 0],
....: "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
....: "col2_c": [0, 0, 1]})
....:
In [13]: pd.from_dummies(df, sep="_")
Out[13]:
col1 col2
0 a b
1 b a
2 a c
``` ### 写入 ORC 文件
新方法 `DataFrame.to_orc()` 允许写入 ORC 文件([GH 43864](https://github.com/pandas-dev/pandas/issues/43864))。
此功能依赖于 [pyarrow](http://arrow.apache.org/docs/python/) 库。 更多详情,请参阅 ORC IO 文档。
警告
+ *强烈建议* 使用 conda 安装 pyarrow,因为 pyarrow 存在一些问题。
+ `to_orc()` 要求 pyarrow>=7.0.0。
+ 目前 Windows 上不支持 `to_orc()`,你可以在 安装可选依赖项 中找到有效的环境。
+ 有关支持的数据类型,请参阅 [Arrow 中 ORC 的支持功能](https://arrow.apache.org/docs/cpp/orc.html#data-types)。
+ 当前在将 DataFrame 转换为 ORC 文件时,日期时间列中的时区信息未被保留。
```py
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
df.to_orc("./out.orc")
``` ### 直接从 TAR 存档中读取
`read_csv()` 或 `DataFrame.to_json()` 等 I/O 方法现在允许直接在 TAR 存档上进行读取和写入([GH 44787](https://github.com/pandas-dev/pandas/issues/44787))。
```py
df = pd.read_csv("./movement.tar.gz")
# ...
df.to_csv("./out.tar.gz")
这支持 .tar、.tar.gz、.tar.bz 和 .tar.xz2 存档。 使用的压缩方法是从文件名推断出来的。 如果无法推断出压缩方法,请使用 compression 参数:
df = pd.read_csv(some_file_obj, compression={"method": "tar", "mode": "r:gz"}) # noqa F821
(其中 mode 是 tarfile.open 的模式之一:docs.python.org/3/library/tarfile.html#tarfile.open) ### read_xml 现在支持 dtype、converters 和 parse_dates
类似于其他 IO 方法,pandas.read_xml() 现在支持将特定的数据类型分配给列,应用转换器方法,并解析日期(GH 43567)。
In [14]: from io import StringIO
In [15]: xml_dates = """<?xml version='1.0' encoding='utf-8'?>
....: <data>
....: <row>
....: <shape>square</shape>
....: <degrees>00360</degrees>
....: <sides>4.0</sides>
....: <date>2020-01-01</date>
....: </row>
....: <row>
....: <shape>circle</shape>
....: <degrees>00360</degrees>
....: <sides/>
....: <date>2021-01-01</date>
....: </row>
....: <row>
....: <shape>triangle</shape>
....: <degrees>00180</degrees>
....: <sides>3.0</sides>
....: <date>2022-01-01</date>
....: </row>
....: </data>"""
....:
In [16]: df = pd.read_xml(
....: StringIO(xml_dates),
....: dtype={'sides': 'Int64'},
....: converters={'degrees': str},
....: parse_dates=['date']
....: )
....:
In [17]: df
Out[17]:
shape degrees sides date
0 square 00360 4 2020-01-01
1 circle 00360 <NA> 2021-01-01
2 triangle 00180 3 2022-01-01
In [18]: df.dtypes
Out[18]:
shape object
degrees object
sides Int64
date datetime64[ns]
dtype: object
``` ### read_xml 现在支持使用 `iterparse` 解析大型 XML
对于可以在数百兆到数千兆范围内变化的非常大的 XML 文件,`pandas.read_xml()` 现在支持使用 [lxml’s iterparse](https://lxml.de/3.2/parsing.html#iterparse-and-iterwalk) 和 [etree’s iterparse](https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse) 进行解析,这是一种内存高效的方法,用于遍历 XML 树并提取特定元素和属性,而无需在内存中保存整个树([GH 45442](https://github.com/pandas-dev/pandas/issues/45442))。
```py
In [1]: df = pd.read_xml(
... "/path/to/downloaded/enwikisource-latest-pages-articles.xml",
... iterparse = {"page": ["title", "ns", "id"]})
... )
df
Out[2]:
title ns id
0 Gettysburg Address 0 21450
1 Main Page 0 42950
2 Declaration by United Nations 0 8435
3 Constitution of the United States of America 0 8435
4 Declaration of Independence (Israel) 0 17858
... ... ... ...
3578760 Page:Black cat 1897 07 v2 n10.pdf/17 104 219649
3578761 Page:Black cat 1897 07 v2 n10.pdf/43 104 219649
3578762 Page:Black cat 1897 07 v2 n10.pdf/44 104 219649
3578763 The History of Tom Jones, a Foundling/Book IX 0 12084291
3578764 Page:Shakespeare of Stratford (1926) Yale.djvu/91 104 21450
[3578765 rows x 3 columns]
``` ### 写时复制
新功能 `copy_on_write` 被添加([GH 46958](https://github.com/pandas-dev/pandas/issues/46958))。写时复制确保从任何方式派生的任何 DataFrame 或 Series 始终表现为副本。写时复制禁止更新任何其他对象,而不是应用方法的对象。
可以通过以下方式启用写时复制:
```py
pd.set_option("mode.copy_on_write", True)
pd.options.mode.copy_on_write = True
或者,可以通过以下方式在本地启用写时复制:
with pd.option_context("mode.copy_on_write", True):
...
没有写时复制,当更新一个由此 DataFrame 派生的子 DataFrame 时,父级 DataFrame 也会更新。
In [19]: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
In [20]: view = df["foo"]
In [21]: view.iloc[0]
Out[21]: 1
In [22]: df
Out[22]:
foo bar
0 1 1
1 2 1
2 3 1
启用写时复制后,df 将不再被更新:
In [23]: with pd.option_context("mode.copy_on_write", True):
....: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
....: view = df["foo"]
....: view.iloc[0]
....: df
....:
更详细的解释可以在这里找到。### 其他增强
-
Series.map()现在在arg为字典但na_action不是None或'ignore'时引发异常(GH 46588) -
MultiIndex.to_frame()现在支持参数allow_duplicates,并且如果缺少或为 False,则在重复标签上引发异常(GH 45245) -
StringArray现在在其构造函数的values参数中接受包含 nan-likes (None,np.nan) 的数组,除了字符串和pandas.NA(GH 40839)。 -
改进了
CategoricalIndex中categories的渲染(GH 45218) -
DataFrame.plot()现在允许subplots参数为指定列组的可迭代列表,以便将列分组在同一子图中(GH 29688) -
to_numeric()现在在降级会生成无法表示为 float32 的值时保留 float64 数组(GH 43693) -
Series.reset_index()和DataFrame.reset_index()现在支持参数allow_duplicates(GH 44410) -
DataFrameGroupBy.min()、SeriesGroupBy.min()、DataFrameGroupBy.max()和SeriesGroupBy.max()现在支持使用engine关键字进行 Numba 执行(GH 45428) -
read_csv()现在支持defaultdict作为dtype参数(GH 41574) -
DataFrame.rolling()和Series.rolling()现在支持具有固定长度窗口的step参数(GH 15354) -
实现了
bool-dtypeIndex,将 bool-dtype 类似数组传递给pd.Index现在将保留booldtype 而不是转换为object(GH 45061) -
实现了复杂数据类型的
Index,向pd.Index传递复杂数据类型的类数组现在会保留复杂数据类型而不是转换为object(GH 45845) -
Series和DataFrame与IntegerDtype现在支持位运算(GH 34463) -
为
DateOffset添加了milliseconds字段支持(GH 43371) -
DataFrame.where()在填充值可以不损失精度的情况下尝试保持DataFrame的数据类型(GH 45582) -
DataFrame.reset_index()现在接受一个names参数,用于重命名索引名称(GH 6878) -
concat()现在在给定levels但keys为 None 时会引发异常(GH 46653) -
concat()现在在levels包含重复值时会引发异常(GH 46653) -
在
DataFrame.corr()、DataFrame.corrwith()、DataFrame.cov()、DataFrame.idxmin()、DataFrame.idxmax()、DataFrameGroupBy.idxmin()、DataFrameGroupBy.idxmax()、DataFrameGroupBy.var()、SeriesGroupBy.var()、DataFrameGroupBy.std()、SeriesGroupBy.std()、DataFrameGroupBy.sem()、SeriesGroupBy.sem()和DataFrameGroupBy.quantile()中添加了numeric_only参数(GH 46560) -
现在在使用
string[pyarrow]数据类型时,如果使用不调度到pyarrow.compute方法的方法,会抛出errors.PerformanceWarning(GH 42613,GH 46725) -
在
DataFrame.join()中添加了validate参数(GH 46622) -
向
Resampler.sum()、Resampler.prod()、Resampler.min()、Resampler.max()、Resampler.first()和Resampler.last()添加了numeric_only参数(GH 46442) -
ExponentialMovingWindow中的times参数现在接受np.timedelta64(GH 47003) -
DataError,SpecificationError,SettingWithCopyError,SettingWithCopyWarning,NumExprClobberingError,UndefinedVariableError,IndexingError,PyperclipException,PyperclipWindowsException,CSSWarning,PossibleDataLossError,ClosedFileError,IncompatibilityWarning,AttributeConflictWarning,DatabaseError,PossiblePrecisionLoss,ValueLabelTypeMismatch,InvalidColumnName, 和CategoricalConversionWarning现在在pandas.errors中暴露出来了 (GH 27656) -
向
testing.assert_series_equal()添加了check_like参数(GH 47247) -
为扩展数组数据类型添加了对
DataFrameGroupBy.ohlc()和SeriesGroupBy.ohlc()的支持(GH 37493) -
允许使用
read_sas()读取压缩的 SAS 文件(例如,.sas7bdat.gz文件) -
pandas.read_html()现在支持从表格单元格中提取链接(GH 13141) -
DatetimeIndex.astype()现在支持将时区无关的索引转换为datetime64[s]、datetime64[ms]和datetime64[us],以及将时区感知的索引转换为相应的datetime64[unit, tzname]数据类型(GH 47579) -
当
dtype为数值且提供了numeric_only=True时,Series的缩减器(例如min、max、sum、mean)现在将成功操作;之前会引发NotImplementedError(GH 47500) -
RangeIndex.union()现在可以返回一个RangeIndex,而不是Int64Index,如果结果值是等间距的(GH 47557,GH 43885) -
DataFrame.compare()现在接受一个result_names参数,允许用户指定正在比较的左侧和右侧 DataFrame 的结果名称。默认为'self'和'other'(GH 44354) -
DataFrame.quantile()增加了一个method参数,可以接受table来评估多列分位数(GH 43881) -
Interval现在支持检查一个区间是否被另一个区间包含(GH 46613) -
在
Series.set_axis()和DataFrame.set_axis()中添加了copy关键字,允许用户在新对象上设置轴而不必复制基础数据(GH 47932) -
方法
ExtensionArray.factorize()接受use_na_sentinel=False以确定如何处理空值(GH 46601) -
Dockerfile现在为 pandas 开发安装了一个专用的pandas-dev虚拟环境,而不是使用base环境([GH 48427](https://github.com/pandas-dev/pandas/issues/48427) ###pandas-stubs
pandas-stubs 库现在得到了 pandas 开发团队的支持,为 pandas API 提供了类型存根。请访问 pandas-dev/pandas-stubs 获取更多信息。
我们感谢 VirtusLab 和 Microsoft 对 pandas-stubs 的最初和重要贡献
原生 PyArrow 支持的 ExtensionArray
安装了 Pyarrow 后,用户现在可以创建由 pyarrow.ChunkedArray 和 pyarrow.DataType 支持的 pandas 对象。
dtype 参数可以接受一个带有 pyarrow 的 pyarrow 数据类型 的字符串,例如 "int64[pyarrow]",或者对于需要参数的 pyarrow 数据类型,可以使用用 pyarrow.DataType 初始化的 ArrowDtype。
In [1]: import pyarrow as pa
In [2]: ser_float = pd.Series([1.0, 2.0, None], dtype="float32[pyarrow]")
In [3]: ser_float
Out[3]:
0 1.0
1 2.0
2 <NA>
dtype: float[pyarrow]
In [4]: list_of_int_type = pd.ArrowDtype(pa.list_(pa.int64()))
In [5]: ser_list = pd.Series([[1, 2], [3, None]], dtype=list_of_int_type)
In [6]: ser_list
Out[6]:
0 [1\. 2.]
1 [ 3\. nan]
dtype: list<item: int64>[pyarrow]
In [7]: ser_list.take([1, 0])
Out[7]:
1 [ 3\. nan]
0 [1\. 2.]
dtype: list<item: int64>[pyarrow]
In [8]: ser_float * 5
Out[8]:
0 5.0
1 10.0
2 <NA>
dtype: float[pyarrow]
In [9]: ser_float.mean()
Out[9]: 1.5
In [10]: ser_float.dropna()
Out[10]:
0 1.0
1 2.0
dtype: float[pyarrow]
大多数操作都得到支持,并且已经使用 pyarrow compute 函数实现。我们建议安装最新版本的 PyArrow 以访问最近实现的计算函数。
警告
此功能是实验性的,API 可能在未来的发布中更改而没有警告。
DataFrame 交换协议实现
Pandas 现在实现了 DataFrame 交换 API 规范。请查看 API 的完整详情 data-apis.org/dataframe-protocol/latest/index.html
该协议由两部分组成:
-
新方法
DataFrame.__dataframe__()用于生成交换对象。它有效地“导出” pandas 数据框作为一个交换对象,因此任何其他实现了该协议的库都可以“导入”该数据框,而无需知道生产者的任何信息,只需知道它生成了一个交换对象。 -
新函数
pandas.api.interchange.from_dataframe()可以从任何符合规范的库中获取任意交换对象,并构建出一个 pandas DataFrame。
Styler
最显著的发展是新方法Styler.concat(),它允许添加自定义页脚行以可视化数据上的其他计算,例如总计和计数等(GH 43875, GH 46186)
另外还有一种替代输出方法Styler.to_string(),允许使用 Styler 的格式化方法创建,例如,CSV 文件(GH 44502)。
还提供了一个新功能Styler.relabel_index(),以提供对索引或列标题显示的完全自定义化(GH 47864)
次要功能改进包括:
在DataFrame.resample()中使用group_keys控制索引
参数group_keys已添加到方法DataFrame.resample()中。与DataFrame.groupby()一样,此参数控制了在使用Resampler.apply()时是否将每个组添加到重新采样中的索引中。
警告
如果不指定 group_keys 参数,将保留先前的行为,并在通过指定 group_keys=False 改变结果时发出警告。在 pandas 的未来版本中,如果不指定 group_keys,将默认使用与 group_keys=False 相同的行为。
In [11]: df = pd.DataFrame(
....: {'a': range(6)},
....: index=pd.date_range("2021-01-01", periods=6, freq="8H")
....: )
....:
In [12]: df.resample("D", group_keys=True).apply(lambda x: x)
Out[12]:
a
2021-01-01 2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [13]: df.resample("D", group_keys=False).apply(lambda x: x)
Out[13]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
以前,结果索引取决于 apply 返回的值,如以下示例所示。
In [1]: # pandas 1.3
In [2]: df.resample("D").apply(lambda x: x)
Out[2]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5
In [3]: df.resample("D").apply(lambda x: x.reset_index())
Out[3]:
index a
2021-01-01 0 2021-01-01 00:00:00 0
1 2021-01-01 08:00:00 1
2 2021-01-01 16:00:00 2
2021-01-02 0 2021-01-02 00:00:00 3
1 2021-01-02 08:00:00 4
2 2021-01-02 16:00:00 5
from_dummies
添加了新函数 from_dummies(),用于将虚拟编码的 DataFrame 转换为分类 DataFrame。
In [11]: import pandas as pd
In [12]: df = pd.DataFrame({"col1_a": [1, 0, 1], "col1_b": [0, 1, 0],
....: "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
....: "col2_c": [0, 0, 1]})
....:
In [13]: pd.from_dummies(df, sep="_")
Out[13]:
col1 col2
0 a b
1 b a
2 a c
写入 ORC 文件
新方法 DataFrame.to_orc() 允许写入 ORC 文件 (GH 43864)。
此功能依赖于 pyarrow 库。有关更多详细信息,请参阅 ORC 上的 IO 文档。
警告
-
强烈建议使用 conda 安装 pyarrow,因为 pyarrow 会出现一些问题。
-
to_orc()需要 pyarrow>=7.0.0。 -
to_orc()在 Windows 上尚不受支持,您可以在 安装可选依赖项 中找到有效的环境。 -
支持的数据类型请参考 Arrow 中 ORC 功能支持。
-
当前在日期时间列中,当数据框转换为 ORC 文件时,时区信息不会被保留。
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
df.to_orc("./out.orc")
直接从 TAR 存档中读取
I/O 方法如 read_csv() 或 DataFrame.to_json() 现在允许直接在 TAR 存档中进行读取和写入 (GH 44787)。
df = pd.read_csv("./movement.tar.gz")
# ...
df.to_csv("./out.tar.gz")
支持 .tar、.tar.gz、.tar.bz 和 .tar.xz2 存档。使用的压缩方法是从文件名推断出来的。如果无法推断出压缩方法,请使用 compression 参数:
df = pd.read_csv(some_file_obj, compression={"method": "tar", "mode": "r:gz"}) # noqa F821
(mode 是 tarfile.open 的模式之一:docs.python.org/3/library/tarfile.html#tarfile.open)
read_xml 现在支持 dtype、converters 和 parse_dates
与其他 IO 方法类似,pandas.read_xml() 现在支持为列分配特定的数据类型、应用转换方法和解析日期 (GH 43567)。
In [14]: from io import StringIO
In [15]: xml_dates = """<?xml version='1.0' encoding='utf-8'?>
....: <data>
....: <row>
....: <shape>square</shape>
....: <degrees>00360</degrees>
....: <sides>4.0</sides>
....: <date>2020-01-01</date>
....: </row>
....: <row>
....: <shape>circle</shape>
....: <degrees>00360</degrees>
....: <sides/>
....: <date>2021-01-01</date>
....: </row>
....: <row>
....: <shape>triangle</shape>
....: <degrees>00180</degrees>
....: <sides>3.0</sides>
....: <date>2022-01-01</date>
....: </row>
....: </data>"""
....:
In [16]: df = pd.read_xml(
....: StringIO(xml_dates),
....: dtype={'sides': 'Int64'},
....: converters={'degrees': str},
....: parse_dates=['date']
....: )
....:
In [17]: df
Out[17]:
shape degrees sides date
0 square 00360 4 2020-01-01
1 circle 00360 <NA> 2021-01-01
2 triangle 00180 3 2022-01-01
In [18]: df.dtypes
Out[18]:
shape object
degrees object
sides Int64
date datetime64[ns]
dtype: object
read_xml 现在支持使用 iterparse 解析大型 XML
对于非常大的 XML 文件,大小可达数百兆字节到数十亿字节,pandas.read_xml() 现在支持使用lxml 的 iterparse和etree 的 iterparse来解析这样大小的文件,这些方法是内存高效的方法,可以迭代遍历 XML 树并提取特定的元素和属性,而不需要将整个树保存在内存中 (GH 45442)。
In [1]: df = pd.read_xml(
... "/path/to/downloaded/enwikisource-latest-pages-articles.xml",
... iterparse = {"page": ["title", "ns", "id"]})
... )
df
Out[2]:
title ns id
0 Gettysburg Address 0 21450
1 Main Page 0 42950
2 Declaration by United Nations 0 8435
3 Constitution of the United States of America 0 8435
4 Declaration of Independence (Israel) 0 17858
... ... ... ...
3578760 Page:Black cat 1897 07 v2 n10.pdf/17 104 219649
3578761 Page:Black cat 1897 07 v2 n10.pdf/43 104 219649
3578762 Page:Black cat 1897 07 v2 n10.pdf/44 104 219649
3578763 The History of Tom Jones, a Foundling/Book IX 0 12084291
3578764 Page:Shakespeare of Stratford (1926) Yale.djvu/91 104 21450
[3578765 rows x 3 columns]
写时复制
新增了一个名为 copy_on_write 的功能 (GH 46958)。写时复制确保任何从其他方式派生的 DataFrame 或 Series 始终表现为副本。写时复制禁止更新除了应用该方法的对象以外的任何其他对象。
可以通过以下方式启用写时复制:
pd.set_option("mode.copy_on_write", True)
pd.options.mode.copy_on_write = True
或者,可以通过以下方式在本地启用写时复制:
with pd.option_context("mode.copy_on_write", True):
...
在没有写时复制的情况下,当更新由该DataFrame派生的子DataFrame时,父 DataFrame也会被更新。
In [19]: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
In [20]: view = df["foo"]
In [21]: view.iloc[0]
Out[21]: 1
In [22]: df
Out[22]:
foo bar
0 1 1
1 2 1
2 3 1
启用写时复制后,df 将不再被更新:
In [23]: with pd.option_context("mode.copy_on_write", True):
....: df = pd.DataFrame({"foo": [1, 2, 3], "bar": 1})
....: view = df["foo"]
....: view.iloc[0]
....: df
....:
更详细的解释可以在这里找到。
其他增强功能
-
Series.map()现在在arg是字典但na_action不是None或'ignore'时会引发异常 (GH 46588)。 -
MultiIndex.to_frame()现在支持参数allow_duplicates,如果该参数缺失或为 False,则在存在重复标签时引发异常 (GH 45245)。 -
StringArray现在在其构造函数的values参数中除了字符串和pandas.NA之外,还接受包含 NaN 类型 (None,np.nan) 的类数组作为输入。(GH 40839) -
改进了
CategoricalIndex中categories的渲染(GH 45218) -
DataFrame.plot()现在允许subplots参数为指定列组的可迭代列表,以便在同一子图中将列分组在一起(GH 29688) -
to_numeric()现在在向下转换时会保留 float64 数组,以防生成无法表示的 float32 值(GH 43693) -
Series.reset_index()和DataFrame.reset_index()现在支持allow_duplicates参数(GH 44410) -
DataFrameGroupBy.min()、SeriesGroupBy.min()、DataFrameGroupBy.max()和SeriesGroupBy.max()现在支持 Numba 执行,使用engine关键字(GH 45428) -
read_csv()现在支持dtype参数为defaultdict(GH 41574) -
DataFrame.rolling()和Series.rolling()现在支持一个step参数来定义固定长度窗口(GH 15354) -
实现了
bool类型的Index,传递一个布尔型数组给pd.Index将保留bool类型而不是转换为object(GH 45061) -
实现了复杂数据类型的
Index,将复杂数据类型数组传递给pd.Index现在将保留复杂数据类型而不是转换为object(GH 45845) -
现在带有
IntegerDtype的Series和DataFrame支持按位运算(GH 34463) -
为
DateOffset添加milliseconds字段支持(GH 43371) -
DataFrame.where()试图保持DataFrame的数据类型,如果填充值可以在不损失精度的情况下转换(GH 45582) -
现在
DataFrame.reset_index()接受一个names参数,用于重命名索引名称(GH 6878) -
当
levels被指定但keys为 None 时,concat()现在会引发异常(GH 46653) -
当
levels包含重复值时,concat()现在会引发异常(GH 46653) -
在
DataFrame.corr()、DataFrame.corrwith()、DataFrame.cov()、DataFrame.idxmin()、DataFrame.idxmax()、DataFrameGroupBy.idxmin()、DataFrameGroupBy.idxmax()、DataFrameGroupBy.var()、SeriesGroupBy.var()、DataFrameGroupBy.std()、SeriesGroupBy.std()、DataFrameGroupBy.sem()、SeriesGroupBy.sem()、以及DataFrameGroupBy.quantile()中添加了numeric_only参数(GH 46560) -
当在使用
string[pyarrow]数据类型的情况下调用不会分派到pyarrow.compute方法的方法时,现在会抛出errors.PerformanceWarning(GH 42613, GH 46725) -
在
DataFrame.join()中添加了validate参数(GH 46622) -
在
Resampler.sum(),Resampler.prod(),Resampler.min(),Resampler.max(),Resampler.first(), 和Resampler.last()中添加了numeric_only参数 (GH 46442) -
ExponentialMovingWindow中的times参数现在接受np.timedelta64(GH 47003) -
DataError,SpecificationError,SettingWithCopyError,SettingWithCopyWarning,NumExprClobberingError,UndefinedVariableError,IndexingError,PyperclipException,PyperclipWindowsException,CSSWarning,PossibleDataLossError,ClosedFileError,IncompatibilityWarning,AttributeConflictWarning,DatabaseError,PossiblePrecisionLoss,ValueLabelTypeMismatch,InvalidColumnName, 和CategoricalConversionWarning现在暴露在pandas.errors(GH 27656) -
在
testing.assert_series_equal()中添加了check_like参数(GH 47247) -
为扩展数组 dtypes 添加了对
DataFrameGroupBy.ohlc()和SeriesGroupBy.ohlc()的支持(GH 37493) -
允许使用
read_sas()读取压缩的 SAS 文件(例如,.sas7bdat.gz文件) -
现在,
pandas.read_html()支持从表格单元中提取链接(GH 13141) -
DatetimeIndex.astype()现在支持将时区无关的索引转换为datetime64[s]、datetime64[ms]和datetime64[us],以及将时区感知的索引转换为相应的datetime64[unit, tzname]dtypes(GH 47579) -
当 dtype 为数值且提供了
numeric_only=True时,Series的减少器(例如,min、max、sum、mean)现在可以成功操作;之前会引发NotImplementedError(GH 47500) -
如果结果值等间隔,
RangeIndex.union()现在可以返回一个RangeIndex而不是一个Int64Index(GH 47557, GH 43885) -
DataFrame.compare()现在接受一个参数result_names,允许用户指定正在比较的左右 DataFrame 的结果名称。 默认情况下是'self'和'other'(GH 44354) -
DataFrame.quantile()增加了一个method参数,可以接受table以计算多列分位数(GH 43881) -
Interval现在支持检查一个区间是否被另一个区间包含(GH 46613) -
在
Series.set_axis()和DataFrame.set_axis()中添加了copy关键字,以允许用户在新对象上设置轴而不必复制基础数据(GH 47932) -
方法
ExtensionArray.factorize()接受use_na_sentinel=False以确定如何处理空值(GH 46601) -
Dockerfile现在为 pandas 开发安装了专用的pandas-dev虚拟环境,而不是使用base环境 (GH 48427)
显着的错误修复
这些是可能具有显着行为更改的错误修复。
使用 groupby 变换时使用 dropna=True
变换是一个其结果与输入大小相同的操作。当结果是一个 DataFrame 或 Series 时,还要求结果的索引与输入的索引相匹配。在 pandas 1.4 中,使用 DataFrameGroupBy.transform() 或 SeriesGroupBy.transform() 与组中的空值和 dropna=True 会产生不正确的结果。下面的示例说明了错误的结果,错误的结果要么包含不正确的值,要么结果的索引与输入不相同。
In [24]: df = pd.DataFrame({'a': [1, 1, np.nan], 'b': [2, 3, 4]})
旧行为:
In [3]: # Value in the last row should be np.nan
df.groupby('a', dropna=True).transform('sum')
Out[3]:
b
0 5
1 5
2 5
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[3]:
b
0 5
1 5
In [3]: # The value in the last row is np.nan interpreted as an integer
df.groupby('a', dropna=True).transform('ffill')
Out[3]:
b
0 2
1 3
2 -9223372036854775808
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x)
Out[3]:
b
0 2
1 3
新行为:
In [25]: df.groupby('a', dropna=True).transform('sum')
Out[25]:
b
0 5.0
1 5.0
2 NaN
In [26]: df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[26]:
b
0 5.0
1 5.0
2 NaN
In [27]: df.groupby('a', dropna=True).transform('ffill')
Out[27]:
b
0 2.0
1 3.0
2 NaN
In [28]: df.groupby('a', dropna=True).transform(lambda x: x)
Out[28]:
b
0 2.0
1 3.0
2 NaN
``` ### 使用 `iso_dates=True` 的 `to_json()` 序列化 tz-naive 时间戳
`DataFrame.to_json()`, `Series.to_json()`, 和 `Index.to_json()` 会将 tz-naive 时间戳的 DatetimeArrays/DatetimeIndexes 不正确地本地化为 UTC。 ([GH 38760](https://github.com/pandas-dev/pandas/issues/38760))
请注意,此补丁不修复将具有时区感知的时间戳本地化为 UTC 的问题。 (相关问题 [GH 12997](https://github.com/pandas-dev/pandas/issues/12997))
*旧行为*
```py
In [32]: index = pd.date_range(
....: start='2020-12-28 00:00:00',
....: end='2020-12-28 02:00:00',
....: freq='1H',
....: )
....:
In [33]: a = pd.Series(
....: data=range(3),
....: index=index,
....: )
....:
In [4]: from io import StringIO
In [5]: a.to_json(date_format='iso')
Out[5]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
In [6]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[6]: array([False, False, False])
新行为
In [34]: from io import StringIO
In [35]: a.to_json(date_format='iso')
Out[35]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
# Roundtripping now works
In [36]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[36]: array([ True, True, True])
``` ### DataFrameGroupBy.value_counts with non-grouping categorical columns and `observed=True`
使用 `observed=True` 调用 `DataFrameGroupBy.value_counts()` 将错误地删除非观察到的非分组列的类别([GH 46357](https://github.com/pandas-dev/pandas/issues/46357))。
```py
In [6]: df = pd.DataFrame(["a", "b", "c"], dtype="category").iloc[0:2]
In [7]: df
Out[7]:
0
0 a
1 b
旧行为
In [8]: df.groupby(level=0, observed=True).value_counts()
Out[8]:
0 a 1
1 b 1
dtype: int64
新行为
In [9]: df.groupby(level=0, observed=True).value_counts()
Out[9]:
0 a 1
1 a 0
b 1
0 b 0
c 0
1 c 0
dtype: int64
``` ### 使用 `groupby` 变换时使用 `dropna=True`
变换是一个其结果与其输入大小相同的操作。当结果是一个 `DataFrame` 或 `Series` 时,还要求结果的索引与输入的索引相匹配。在 pandas 1.4 中,使用带有组中空值且 `dropna=True` 的 `DataFrameGroupBy.transform()` 或 `SeriesGroupBy.transform()` 会导致不正确的结果。通过以下示例进行演示,不正确的结果可能包含不正确的值,或结果的索引与输入不匹配。
```py
In [24]: df = pd.DataFrame({'a': [1, 1, np.nan], 'b': [2, 3, 4]})
旧行为:
In [3]: # Value in the last row should be np.nan
df.groupby('a', dropna=True).transform('sum')
Out[3]:
b
0 5
1 5
2 5
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[3]:
b
0 5
1 5
In [3]: # The value in the last row is np.nan interpreted as an integer
df.groupby('a', dropna=True).transform('ffill')
Out[3]:
b
0 2
1 3
2 -9223372036854775808
In [3]: # Should have one additional row with the value np.nan
df.groupby('a', dropna=True).transform(lambda x: x)
Out[3]:
b
0 2
1 3
新行为:
In [25]: df.groupby('a', dropna=True).transform('sum')
Out[25]:
b
0 5.0
1 5.0
2 NaN
In [26]: df.groupby('a', dropna=True).transform(lambda x: x.sum())
Out[26]:
b
0 5.0
1 5.0
2 NaN
In [27]: df.groupby('a', dropna=True).transform('ffill')
Out[27]:
b
0 2.0
1 3.0
2 NaN
In [28]: df.groupby('a', dropna=True).transform(lambda x: x)
Out[28]:
b
0 2.0
1 3.0
2 NaN
使用 iso_dates=True 时序列化时区非感知的时间戳
DataFrame.to_json()、Series.to_json() 和 Index.to_json() 将错误地将时区非感知时间戳本地化为 UTC。(GH 38760)
注意,此补丁不修复在序列化时将时区感知时间戳本地化为 UTC 的问题。(相关问题见 GH 12997)
旧行为
In [32]: index = pd.date_range(
....: start='2020-12-28 00:00:00',
....: end='2020-12-28 02:00:00',
....: freq='1H',
....: )
....:
In [33]: a = pd.Series(
....: data=range(3),
....: index=index,
....: )
....:
In [4]: from io import StringIO
In [5]: a.to_json(date_format='iso')
Out[5]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
In [6]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[6]: array([False, False, False])
新行为
In [34]: from io import StringIO
In [35]: a.to_json(date_format='iso')
Out[35]: '{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
# Roundtripping now works
In [36]: pd.read_json(StringIO(a.to_json(date_format='iso')), typ="series").index == a.index
Out[36]: array([ True, True, True])
使用 observed=True 时 DataFrameGroupBy.value_counts 的非分组分类列
使用 observed=True 调用 DataFrameGroupBy.value_counts() 将错误地删除非观察到的非分组列的类别(GH 46357)。
In [6]: df = pd.DataFrame(["a", "b", "c"], dtype="category").iloc[0:2]
In [7]: df
Out[7]:
0
0 a
1 b
旧行为
In [8]: df.groupby(level=0, observed=True).value_counts()
Out[8]:
0 a 1
1 b 1
dtype: int64
新行为
In [9]: df.groupby(level=0, observed=True).value_counts()
Out[9]:
0 a 1
1 a 0
b 1
0 b 0
c 0
1 c 0
dtype: int64
不兼容的后向 API 更改
增加了依赖项的最低版本
一些依赖项的最低支持版本已更新。如果安装了,现在我们要求:
| 包 | 最低版本 | 必需 | 已更改 |
|---|---|---|---|
| numpy | 1.20.3 | X | X |
| mypy (dev) | 0.971 | X | |
| beautifulsoup4 | 4.9.3 | X | |
| blosc | 1.21.0 | X | |
| bottleneck | 1.3.2 | X | |
| fsspec | 2021.07.0 | X | |
| hypothesis | 6.13.0 | X | |
| gcsfs | 2021.07.0 | X | |
| jinja2 | 3.0.0 | X | |
| lxml | 4.6.3 | X | |
| numba | 0.53.1 | X | |
| numexpr | 2.7.3 | X | |
| openpyxl | 3.0.7 | X | |
| pandas-gbq | 0.15.0 | X | |
| psycopg2 | 2.8.6 | X | |
| pymysql | 1.0.2 | X | |
| pyreadstat | 1.1.2 | X | |
| pyxlsb | 1.0.8 | X | |
| s3fs | 2021.08.0 | X | |
| scipy | 1.7.1 | X | |
| sqlalchemy | 1.4.16 | X | |
| tabulate | 0.8.9 | X | |
| xarray | 0.19.0 | X | |
| xlsxwriter | 1.4.3 | X |
对于可选库,一般建议使用最新版本。以下表格列出了在 pandas 开发过程中当前正在测试的每个库的最低版本。低于最低测试版本的可选库可能仍然可以工作,但不被视为受支持。
| Package | Minimum Version | Changed |
|---|---|---|
| beautifulsoup4 | 4.9.3 | X |
| blosc | 1.21.0 | X |
| bottleneck | 1.3.2 | X |
| brotlipy | 0.7.0 | |
| fastparquet | 0.4.0 | |
| fsspec | 2021.08.0 | X |
| html5lib | 1.1 | |
| hypothesis | 6.13.0 | X |
| gcsfs | 2021.08.0 | X |
| jinja2 | 3.0.0 | X |
| lxml | 4.6.3 | X |
| matplotlib | 3.3.2 | |
| numba | 0.53.1 | X |
| numexpr | 2.7.3 | X |
| odfpy | 1.4.1 | |
| openpyxl | 3.0.7 | X |
| pandas-gbq | 0.15.0 | X |
| psycopg2 | 2.8.6 | X |
| pyarrow | 1.0.1 | |
| pymysql | 1.0.2 | X |
| pyreadstat | 1.1.2 | X |
| pytables | 3.6.1 | |
| python-snappy | 0.6.0 | |
| pyxlsb | 1.0.8 | X |
| s3fs | 2021.08.0 | X |
| scipy | 1.7.1 | X |
| sqlalchemy | 1.4.16 | X |
| tabulate | 0.8.9 | X |
| tzdata | 2022a | |
| xarray | 0.19.0 | X |
| xlrd | 2.0.1 | |
| xlsxwriter | 1.4.3 | X |
| xlwt | 1.3.0 | |
| zstandard | 0.15.2 |
查看依赖项和可选依赖项以获取更多信息。 ### 其他 API 更改
-
BigQuery I/O 方法
read_gbq()和DataFrame.to_gbq()默认为auth_local_webserver = True。Google 已经弃用了auth_local_webserver = False“out of band” (copy-paste) 流程。auth_local_webserver = False选项计划在 2022 年 10 月停止工作。(GH 46312) -
read_json()现在在输入为以.json、.json.gz、.json.bz2等结尾的字符串但不存在此类文件时,引发FileNotFoundError(之前是ValueError)(GH 29102) -
先前会引发
OverflowError的Timestamp或Timedelta的操作现在会在适当的情况下引发OutOfBoundsDatetime或OutOfBoundsTimedelta(GH 47268) -
先前
read_sas()返回None时,现在返回一个空的DataFrame(GH 47410) -
DataFrame构造函数现在在index或columns参数为集合时引发异常(GH 47215)### 增加了依赖项的最低版本
一些依赖项的最低支持版本已更新。如果安装,我们现在需要:
| Package | 最低版本 | 需要 | 更改 |
|---|---|---|---|
| numpy | 1.20.3 | X | X |
| mypy (dev) | 0.971 | X | |
| beautifulsoup4 | 4.9.3 | X | |
| blosc | 1.21.0 | X | |
| bottleneck | 1.3.2 | X | |
| fsspec | 2021.07.0 | X | |
| hypothesis | 6.13.0 | X | |
| gcsfs | 2021.07.0 | X | |
| jinja2 | 3.0.0 | X | |
| lxml | 4.6.3 | X | |
| numba | 0.53.1 | X | |
| numexpr | 2.7.3 | X | |
| openpyxl | 3.0.7 | X | |
| pandas-gbq | 0.15.0 | X | |
| psycopg2 | 2.8.6 | X | |
| pymysql | 1.0.2 | X | |
| pyreadstat | 1.1.2 | X | |
| pyxlsb | 1.0.8 | X | |
| s3fs | 2021.08.0 | X | |
| scipy | 1.7.1 | X | |
| sqlalchemy | 1.4.16 | X | |
| tabulate | 0.8.9 | X | |
| xarray | 0.19.0 | X | |
| xlsxwriter | 1.4.3 | X |
对于可选库,一般建议使用最新版本。以下表格列出了在 pandas 开发过程中当前正在测试的每个库的最低版本。低于最低测试版本的可选库可能仍然可用,但不被视为受支持。
| Package | 最低版本 | 更改 |
|---|---|---|
| beautifulsoup4 | 4.9.3 | X |
| blosc | 1.21.0 | X |
| bottleneck | 1.3.2 | X |
| brotlipy | 0.7.0 | |
| fastparquet | 0.4.0 | |
| fsspec | 2021.08.0 | X |
| html5lib | 1.1 | |
| hypothesis | 6.13.0 | X |
| gcsfs | 2021.08.0 | X |
| jinja2 | 3.0.0 | X |
| lxml | 4.6.3 | X |
| matplotlib | 3.3.2 | |
| numba | 0.53.1 | X |
| numexpr | 2.7.3 | X |
| odfpy | 1.4.1 | |
| openpyxl | 3.0.7 | X |
| pandas-gbq | 0.15.0 | X |
| psycopg2 | 2.8.6 | X |
| pyarrow | 1.0.1 | |
| pymysql | 1.0.2 | X |
| pyreadstat | 1.1.2 | X |
| pytables | 3.6.1 | |
| python-snappy | 0.6.0 | |
| pyxlsb | 1.0.8 | X |
| s3fs | 2021.08.0 | X |
| scipy | 1.7.1 | X |
| sqlalchemy | 1.4.16 | X |
| tabulate | 0.8.9 | X |
| tzdata | 2022a | |
| xarray | 0.19.0 | X |
| xlrd | 2.0.1 | |
| xlsxwriter | 1.4.3 | X |
| xlwt | 1.3.0 | |
| zstandard | 0.15.2 |
更多信息,请参阅 Dependencies 和 Optional dependencies。
其他 API 变更
-
BigQuery I/O 方法
read_gbq()和DataFrame.to_gbq()默认为auth_local_webserver = True。Google 已弃用auth_local_webserver = False的 “out of band” (copy-paste) 流程。auth_local_webserver = False选项计划于 2022 年 10 月停止工作。(GH 46312) -
read_json()现在在输入为以.json、.json.gz、.json.bz2等结尾的字符串但不存在此类文件时,会引发FileNotFoundError异常(先前为ValueError)。(GH 29102) -
对
Timestamp或Timedelta的操作,在先前会引发OverflowError的情况下,现在在适当的情况下引发OutOfBoundsDatetime或OutOfBoundsTimedelta。(GH 47268) -
当
read_sas()先前返回None时,现在返回一个空的DataFrame。(GH 47410) -
DataFrame构造函数在index或columns参数为集合时引发异常。(GH 47215)
废弃
警告
在下一个主要版本发布 2.0 时,考虑进行几个较大的 API 更改,没有正式弃用,例如将标准库 zoneinfo 作为默认的时区实现,而不是 pytz,使 Index 支持所有数据类型而不是具有多个子类(CategoricalIndex、Int64Index 等),等等。正在考虑的更改已记录在 这个 GitHub issue 中,欢迎任何反馈或关注。
基于标签的整数切片在具有 Int64Index 或 RangeIndex 的 Series 上
在将来的版本中,在具有 Int64Index 或 RangeIndex 的 Series 上进行的整数切片将被视为 基于标签,而不是基于位置的。这将使行为与其他 Series.__getitem__() 和 Series.__setitem__() 的行为一致 (GH 45162).
例如:
In [29]: ser = pd.Series([1, 2, 3, 4, 5], index=[2, 3, 5, 7, 11])
在旧的行为中,ser[2:4] 将切片视为位置的:
旧行为:
In [3]: ser[2:4]
Out[3]:
5 3
7 4
dtype: int64
在将来的版本中,这将被视为基于标签:
未来行为:
In [4]: ser.loc[2:4]
Out[4]:
2 1
3 2
dtype: int64
要保留旧行为,请使用 series.iloc[i:j]。 要获得未来行为,请使用 series.loc[i:j]。
对 DataFrame 的切片不会受到影响。 ### ExcelWriter 属性
所有ExcelWriter的属性以前被记录为非公开。但是,一些第三方 Excel 引擎记录了访问 ExcelWriter.book 或 ExcelWriter.sheets,并且用户正在使用这些属性,可能还有其他属性。以前这些属性不安全使用;例如,对 ExcelWriter.book 的修改不会更新 ExcelWriter.sheets,反之亦然。为了支持这一点,pandas 已经将一些属性公开并改进了它们的实现,以便现在可以安全使用它们。 (GH 45572)
以下属性现在是公开的并且被认为是安全可访问的。
bookcheck_extensionclosedate_formatdatetime_formatengineif_sheet_existssheetssupported_extensions
以下属性已经被弃用。 当访问时,它们现在会引发一个 FutureWarning 并且将在将来的版本中被移除。 用户应该注意到它们的使用被认为是不安全的,并且可能导致意外结果。
cur_sheethandlespathsavewrite_cells
有关详细信息,请参阅 ExcelWriter 的文档。### 在 DataFrameGroupBy.apply() 和 SeriesGroupBy.apply() 中使用 group_keys 的转换器
在以前的 pandas 版本中,如果推断 DataFrameGroupBy.apply() 或 SeriesGroupBy.apply() 传递的函数是一个转换器(即结果索引等于输入索引),则 DataFrame.groupby() 和 Series.groupby() 的 group_keys 参数会被忽略,并且组键永远不会添加到结果的索引中。在将来,当用户指定 group_keys=True 时,将会将组键添加到索引中。
由于 group_keys=True 是 DataFrame.groupby() 和 Series.groupby() 的默认值,未指定带有转换器的 group_keys 将引发 FutureWarning。可以通过指定 group_keys=False 来消除此警告并保留以前的行为。
使用 loc 和 iloc 设置值时的原地操作
大多数情况下,使用 DataFrame.iloc() 设置值会尝试原地操作,仅在必要时回退到插入新数组。有些情况下不遵循此规则,例如,从具有不同 dtype 的数组设置整个列时:
In [30]: df = pd.DataFrame({'price': [11.1, 12.2]}, index=['book1', 'book2'])
In [31]: original_prices = df['price']
In [32]: new_prices = np.array([98, 99])
旧行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, float: 64
此行为已弃用。在将来版本中,使用 iloc 设置整列将尝试原地操作。
未来行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98.0
book2 99.0
Name: price, dtype: float64
In [5]: original_prices
Out[5]:
book1 98.0
book2 99.0
Name: price, dtype: float64
要获取旧行为,请直接使用 DataFrame.__setitem__():
In [3]: df[df.columns[0]] = new_prices
In [4]: df.iloc[:, 0]
Out[4]
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, dtype: float64
要在 df.columns 不唯一且您想通过索引更改单个列时获得旧行为,您可以使用 DataFrame.isetitem(),该方法已添加到 pandas 1.5 中:
In [3]: df_with_duplicated_cols = pd.concat([df, df], axis='columns')
In [3]: df_with_duplicated_cols.isetitem(0, new_prices)
In [4]: df_with_duplicated_cols.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: 0, dtype: float64
numeric_only 默认值
在DataFrame、DataFrameGroupBy和Resampler操作中,例如min、sum和idxmax,如果存在numeric_only参数的默认值,那么默认值是不一致的。此外,具有默认值None的操作可能导致意外的结果。(GH 46560)
In [1]: df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
In [2]: # Reading the next line without knowing the contents of df, one would
# expect the result to contain the products for both columns a and b.
df[["a", "b"]].prod()
Out[2]:
a 2
dtype: int64
为了避免这种行为,已经弃用了指定值numeric_only=None,并将在未来版本的 pandas 中删除。未来,所有带有numeric_only参数的操作将默认为False。用户应该只对可以进行操作的列调用操作,或者指定numeric_only=True来仅对布尔值、整数和浮点数列进行操作。
为了支持向新行为过渡,以下方法已获得了numeric_only参数。
-
DataFrame.corr() -
DataFrame.corrwith() -
DataFrame.cov() -
DataFrame.idxmin() -
DataFrame.idxmax() -
DataFrameGroupBy.cummin() -
DataFrameGroupBy.cummax() -
DataFrameGroupBy.idxmin() -
DataFrameGroupBy.idxmax() -
DataFrameGroupBy.var() -
DataFrameGroupBy.std() -
DataFrameGroupBy.sem() -
DataFrameGroupBy.quantile() -
Resampler.mean() -
Resampler.median() -
Resampler.sem() -
Resampler.std() -
Resampler.var() -
DataFrame.rolling()操作 -
DataFrame.expanding()操作 -
DataFrame.ewm()操作 ### 其他弃用项 -
弃用关键字
line_terminator在DataFrame.to_csv()和Series.to_csv()中,请改用lineterminator;这是为了与read_csv()和标准库‘csv’模块保持一致(GH 9568) -
SparseArray.astype()、Series.astype()和DataFrame.astype()在传递非稀疏dtype时的弃用行为。在将来的版本中,这将转换为非稀疏 dtype,而不是将其包装在SparseDtype中(GH 34457) -
DatetimeIndex.intersection()和DatetimeIndex.symmetric_difference()的弃用行为(union行为在版本 1.3.0 中已弃用)与混合时区;在将来的版本中,两者都将转换为 UTC 而不是对象 dtype(GH 39328, GH 45357) -
弃用了
DataFrame.iteritems(),Series.iteritems(),HDFStore.iteritems(),改为使用DataFrame.items(),Series.items(),HDFStore.items()(GH 45321) -
弃用了
Series.is_monotonic()和Index.is_monotonic(),改为使用Series.is_monotonic_increasing()和Index.is_monotonic_increasing()(GH 45422, GH 21335) -
弃用了
DatetimeIndex.astype(),TimedeltaIndex.astype(),PeriodIndex.astype()在转换为除int64之外的整数 dtype 时的行为。在将来的版本中,这些将转换为确切指定的 dtype(而不总是int64),并且如果转换溢出将引发异常 (GH 45034) -
弃用了 DataFrame 和 Series 的
__array_wrap__方法,改为依赖标准的 numpy ufuncs (GH 45451) -
弃用了在将带有时区的 float-dtype 数据传递给
Series或DatetimeIndex时将其视为壁钟时间的行为 (GH 45573) -
弃用了在
fillna()中使用timedelta64[ns]dtype 和不兼容的填充值的行为;在将来的版本中,这将转换为一个通用的 dtype(通常是 object),而不是引发异常,与其他 dtype 的行为一致 (GH 45746) -
弃用了
infer_freq()中的warn参数 (GH 45947) -
弃用了在
ExtensionArray.argsort()中允许非关键字参数的行为 (GH 46134) -
废弃了在
DataFrame.any()和DataFrame.all()中将所有布尔类型的object列视为布尔型,使用bool_only=True显式地转换为布尔型(GH 46188)。 -
废弃了方法
DataFrame.quantile()的行为,属性numeric_only默认为 False。结果中包括了日期时间列和时间增量列(GH 7308)。 -
废弃了
Timedelta.freq和Timedelta.is_populated(GH 46430)。 -
废弃了
Timedelta.delta(GH 46476)。 -
废弃了在
DataFrame.any()和Series.any()中将参数作为位置参数传递的行为(GH 44802)。 -
废弃了在
DataFrame.pivot()和pivot()中除了data以外的位置参数传递(GH 30228)。 -
废弃了方法
DataFrame.mad()、Series.mad()以及相应的 groupby 方法(GH 11787)。 -
废弃了在
Index.join()中除了other以外的位置参数传递,使用关键字参数而不是位置参数(GH 46518)。 -
废弃了在
StringMethods.rsplit()和StringMethods.split()中除了pat以外的位置参数传递,使用关键字参数而不是位置参数(GH 47423)。 -
废弃了在时区未指定的
DatetimeIndex上使用代表时区感知的字符串进行索引的行为(GH 46903,GH 36148)。 -
废弃了在
Timestamp构造函数中允许使用非整数值的unit="M"或unit="Y"(GH 47267)。 -
废弃了
display.column_space全局配置选项(GH 7576)。 -
废弃了
factorize()、Index.factorize()和ExtensionArray.factorize()方法中的na_sentinel参数;改为传递use_na_sentinel=True以使用哨兵-1表示 NaN 值,传递use_na_sentinel=False代替na_sentinel=None来编码 NaN 值(GH 46910) -
废弃了当用户定义函数返回 DataFrame 时,
DataFrameGroupBy.transform()不对齐结果的行为(GH 45648) -
对于无法按照指定的
dayfirst参数解析分隔日期的情况,从to_datetime()发出了更清晰的警告(GH 46210) -
即使对于省略了前导零的日期(例如
31/1/2001),to_datetime()也会发出警告,无法按照指定的dayfirst参数解析分隔日期(GH 47880) -
废弃了当数据类型为非数字且提供了
numeric_only=True参数时,Series和Resampler缩减器(如min、max、sum、mean)引发NotImplementedError错误的行为;在将来的版本中,这将引发TypeError错误(GH 47500) -
废弃了
Series.rank()在非数字类型的情况下,提供了numeric_only=True参数时返回空结果;在将来的版本中,这将引发TypeError错误(GH 47500) -
废弃了
Series.mask()、Series.where()、DataFrame.mask()和DataFrame.where()方法中的errors参数,因为errors对这些方法没有影响(GH 47728) -
已废弃
Rolling、Expanding和ExponentialMovingWindow操作中的未使用的参数*args和**kwargs(GH 47836)。 -
已废弃
Categorical.set_ordered()、Categorical.as_ordered()和Categorical.as_unordered()中的inplace关键字(GH 37643)。 -
已废弃使用
cat.categories = ['a', 'b', 'c']设置分类的类别,请改用Categorical.rename_categories()(GH 37643)。 -
已废弃
Series.to_excel()和DataFrame.to_excel()中未使用的参数encoding和verbose(GH 47912)。 -
已废弃
DataFrame.set_axis()和Series.set_axis()中的inplace关键字,请改用obj = obj.set_axis(..., copy=False)(GH 48130)。 -
已废弃对被长度为 1 的列表分组的
DataFrameGroupBy或SeriesGroupBy进行迭代时产生单个元素;将返回长度为 1 的元组(GH 42795)。 -
已修复
MultiIndex.lesort_depth()作为公共方法的废弃警告消息,因为先前的消息是指MultiIndex.is_lexsorted()(GH 38701)。 -
已废弃
DataFrame.plot()和Series.plot()中的sort_columns参数(GH 47563)。 -
对于除
DataFrame.to_stata()和read_stata()的第一个参数之外的所有位置参数,已废弃,请改用关键字参数代替(GH 48128)。 -
在
read_csv()、read_fwf()、read_table()和read_excel()中弃用了mangle_dupe_cols参数。该参数从未被实现,并且将添加一个新参数,可以在其中指定重命名模式 (GH 47718) -
弃用了在
Series.astype()中允许dtype='datetime64'或dtype=np.datetime64,请改用“datetime64[ns]” (GH 47844) ### 基于标签的整数切片,对于具有 Int64Index 或 RangeIndex 的 Series
在将来的版本中,对具有 Int64Index 或 RangeIndex 的 Series 进行整数切片将被视为 基于标签,而不是位置。这将使行为与其他 Series.__getitem__() 和 Series.__setitem__() 的行为一致 (GH 45162)。
例如:
In [29]: ser = pd.Series([1, 2, 3, 4, 5], index=[2, 3, 5, 7, 11])
在旧行为中,ser[2:4]将切片视为位置:
旧行为:
In [3]: ser[2:4]
Out[3]:
5 3
7 4
dtype: int64
在将来的版本中,这将被视为基于标签:
未来行为:
In [4]: ser.loc[2:4]
Out[4]:
2 1
3 2
dtype: int64
要保留旧行为,请使用series.iloc[i:j]。要获取未来行为,请使用series.loc[i:j]。
在DataFrame上进行切片不会受到影响。
ExcelWriter 属性
所有ExcelWriter的属性先前都被记录为非公开的。然而,一些第三方 Excel 引擎记录了对ExcelWriter.book或ExcelWriter.sheets的访问,用户正在使用这些属性,可能还有其他属性。先前这些属性不安全使用;例如,对ExcelWriter.book的修改不会更新ExcelWriter.sheets,反之亦然。为了支持这一点,pandas 已经将一些属性公开,并改进了它们的实现,以便现在可以安全地使用它们。(GH 45572)
以下属性现在是公开的,并被认为是安全访问的。
bookcheck_extensionclosedate_formatdatetime_formatengineif_sheet_existssheetssupported_extensions
当访问以下属性时已被弃用。当访问时现在会引发 FutureWarning 并将在将来的版本中删除。用户应该注意,它们的使用被认为是不安全的,并且可能导致意外结果。
cur_sheethandlespathsavewrite_cells
有关详细信息,请参阅ExcelWriter的文档。
在 DataFrameGroupBy.apply() 和 SeriesGroupBy.apply() 中使用 group_keys
在 pandas 的早期版本中,如果推断 DataFrameGroupBy.apply() 或 SeriesGroupBy.apply() 传递的函数是转换器(即生成的索引等于输入索引),则 DataFrame.groupby() 和 Series.groupby() 的 group_keys 参数将被忽略,并且组键永远不会被添加到结果的索引中。未来,当用户指定 group_keys=True 时,组键将添加到索引中。
由于 group_keys=True 是 DataFrame.groupby() 和 Series.groupby() 的默认值,如果不使用转换器指定 group_keys,将会引发 FutureWarning。可以通过指定 group_keys=False 来消除此警告并保留以前的行为。
使用 loc 和 iloc 设置值时的原位操作
大多数情况下,使用 DataFrame.iloc() 设置值会尝试原地设置值,仅在必要时回退到插入新数组。有些情况下不会遵循此规则,例如使用不同 dtype 的数组设置整个列时:
In [30]: df = pd.DataFrame({'price': [11.1, 12.2]}, index=['book1', 'book2'])
In [31]: original_prices = df['price']
In [32]: new_prices = np.array([98, 99])
旧行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, float: 64
此行为已被弃用。在将来的版本中,使用 iloc 设置整个列将尝试原地操作。
未来的行为:
In [3]: df.iloc[:, 0] = new_prices
In [4]: df.iloc[:, 0]
Out[4]:
book1 98.0
book2 99.0
Name: price, dtype: float64
In [5]: original_prices
Out[5]:
book1 98.0
book2 99.0
Name: price, dtype: float64
要获得旧的行为,请直接使用 DataFrame.__setitem__():
In [3]: df[df.columns[0]] = new_prices
In [4]: df.iloc[:, 0]
Out[4]
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: price, dtype: float64
当df.columns不唯一且您想按索引更改单个列时,可以使用在 pandas 1.5 中添加的DataFrame.isetitem()来获得旧的行为:
In [3]: df_with_duplicated_cols = pd.concat([df, df], axis='columns')
In [3]: df_with_duplicated_cols.isetitem(0, new_prices)
In [4]: df_with_duplicated_cols.iloc[:, 0]
Out[4]:
book1 98
book2 99
Name: price, dtype: int64
In [5]: original_prices
Out[5]:
book1 11.1
book2 12.2
Name: 0, dtype: float64
numeric_only 默认值
在DataFrame、DataFrameGroupBy和Resampler操作中,如min、sum和idxmax,numeric_only参数的默认值(如果存在)是不一致的。此外,默认值为None的操作可能导致意外结果。(GH 46560)
In [1]: df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
In [2]: # Reading the next line without knowing the contents of df, one would
# expect the result to contain the products for both columns a and b.
df[["a", "b"]].prod()
Out[2]:
a 2
dtype: int64
为避免这种行为,已弃用指定值为numeric_only=None,并将在未来的 pandas 版本中移除。未来,所有带有numeric_only参数的操作将默认为False。用户应该只对可以操作的列调用操作,或者指定numeric_only=True仅对布尔值、整数和浮点数列进行操作。
为了支持过渡到新行为,以下方法已增加了numeric_only参数。
-
DataFrame.corr() -
DataFrame.corrwith() -
DataFrame.cov() -
DataFrame.idxmin() -
DataFrame.idxmax() -
DataFrameGroupBy.cummin() -
DataFrameGroupBy.cummax() -
DataFrameGroupBy.idxmin() -
DataFrameGroupBy.idxmax() -
DataFrameGroupBy.var() -
DataFrameGroupBy.std() -
DataFrameGroupBy.sem()的sem()方法 -
DataFrameGroupBy.quantile()的quantile()方法 -
Resampler.mean()的mean()方法 -
Resampler.median()的median()方法 -
Resampler.sem()的sem()方法 -
Resampler.std()的std()方法 -
Resampler.var()的var()方法 -
DataFrame.rolling()操作 -
DataFrame.expanding()操作 -
DataFrame.ewm()操作
其他弃用
-
在
DataFrame.to_csv()和Series.to_csv()中弃用了关键字line_terminator,改用lineterminator;这是为了与read_csv()和标准库中的‘csv’模块保持一致 (GH 9568) -
当传递非稀疏
dtype时,弃用了SparseArray.astype()、Series.astype()和DataFrame.astype()的行为。在将来的版本中,这将转换为非稀疏的dtype而不是将其包装在SparseDtype中 (GH 34457) -
弃用了
DatetimeIndex.intersection()和DatetimeIndex.symmetric_difference()的行为(union行为在版本 1.3.0 中已经弃用)与混合时区;在将来的版本中,两者都将转换为 UTC 而不是对象数据类型(GH 39328,GH 45357) -
弃用了
DataFrame.iteritems(),Series.iteritems(),HDFStore.iteritems(),推荐使用DataFrame.items(),Series.items(),HDFStore.items()(GH 45321) -
弃用了
Series.is_monotonic()和Index.is_monotonic(),推荐使用Series.is_monotonic_increasing()和Index.is_monotonic_increasing()(GH 45422,GH 21335) -
当转换为除
int64之外的整数数据类型时,弃用了DatetimeIndex.astype(),TimedeltaIndex.astype(),PeriodIndex.astype()的行为。在将来的版本中,这些将转换为指定的数据类型(而不总是int64),并且如果转换溢出将引发异常(GH 45034) -
弃用了 DataFrame 和 Series 的
__array_wrap__方法,应依赖于标准的 numpy ufuncs 代替(GH 45451) -
当将 float 数据类型数据与时区一起传递给
Series或DatetimeIndex时,弃用了将 float 数据类型数据视为墙时的行为(GH 45573) -
对于
timedelta64[ns]数据类型和不兼容的填充值,弃用了Series.fillna()和DataFrame.fillna()的行为;在将来的版本中,这将转换为一个通用数据类型(通常是对象),而不是引发异常,以匹配其他数据类型的行为(GH 45746) -
弃用了
infer_freq()中的warn参数(GH 45947) -
弃用了在
ExtensionArray.argsort()中允许非关键字参数的方式(GH 46134) -
弃用了在
DataFrame.any()和DataFrame.all()中将所有布尔类型object列视为类似布尔值的方式,使用bool_only=True时,显式转换为布尔值而不是默认行为(GH 46188) -
弃用了方法
DataFrame.quantile()的行为,属性numeric_only默认为 False。结果中包括日期时间/时间增量列(GH 7308) -
弃用了
Timedelta.freq和Timedelta.is_populated(GH 46430) -
弃用了
Timedelta.delta(GH 46476) -
弃用了在
DataFrame.any()和Series.any()中将参数作为位置参数传递的方式(GH 44802) -
弃用了在
DataFrame.pivot()和pivot()中的位置参数传递方式,除了data(GH 30228) -
弃用了方法
DataFrame.mad(),Series.mad()以及相应的分组方法(GH 11787) -
弃用了在
Index.join()中的位置参数传递方式,除了other,使用关键字参数而不是位置参数(GH 46518) -
弃用了在
StringMethods.rsplit()和StringMethods.split()中的位置参数传递方式,除了pat,使用关键字参数而不是位置参数(GH 47423) -
弃用了使用代表时区感知日期时间的字符串对时区无关的
DatetimeIndex进行索引的方式(GH 46903,GH 36148) -
在非圆整浮点值的情况下,弃用允许在
Timestamp构造函数中使用unit="M"或unit="Y"参数(GH 47267) -
弃用
display.column_space全局配置选项(GH 7576) -
弃用参数
na_sentinel在factorize()、Index.factorize()和ExtensionArray.factorize()中;改用use_na_sentinel=True以使用 sentinel-1表示 NaN 值,以及改用use_na_sentinel=False代替na_sentinel=None来编码 NaN 值(GH 46910) -
弃用
DataFrameGroupBy.transform()方法在用户自定义函数返回 DataFrame 时不会对结果进行对齐(GH 45648) -
当分隔日期无法根据指定的
dayfirst参数进行解析时,从to_datetime()中澄清警告(GH 46210) -
即使对于省略前导零的日期(例如
31/1/2001),当分隔日期无法根据指定的dayfirst参数进行解析时,从to_datetime()中发出警告(GH 47880) -
当 dtype 非数字且提供了
numeric_only=True时,弃用Series和Resamplerreducers(例如min、max、sum、mean)引发NotImplementedError;这在将来的版本中将引发TypeError(GH 47500) -
当 dtype 非数字且提供了
numeric_only=True时,弃用Series.rank()返回空结果;这在将来的版本中将引发TypeError(GH 47500) -
对于
Series.mask()、Series.where()、DataFrame.mask()和DataFrame.where()方法,废弃了参数errors,因为这些方法上的errors参数没有任何效果(GH 47728) -
在
Rolling、Expanding和ExponentialMovingWindow操作中废弃了参数*args和**kwargs(GH 47836) -
废弃了在
Categorical.set_ordered()、Categorical.as_ordered()和Categorical.as_unordered()中使用inplace关键字(GH 37643) -
废弃了使用
cat.categories = ['a', 'b', 'c']设置分类的类别,改用Categorical.rename_categories()代替(GH 37643) -
在
Series.to_excel()和DataFrame.to_excel()中废弃了未使用的参数encoding和verbose(GH 47912) -
在
DataFrame.set_axis()和Series.set_axis()中废弃了inplace关键字,改用obj = obj.set_axis(..., copy=False)代替(GH 48130) -
废弃了在通过长度为 1 的列表分组的
DataFrameGroupBy或SeriesGroupBy上迭代时产生单个元素的行为;而将返回长度为 1 的元组(GH 42795) -
修正了
MultiIndex.lesort_depth()作为公共方法的弃用警告消息,因为先前的消息引用了MultiIndex.is_lexsorted()而不是该方法本身(GH 38701) -
在
DataFrame.plot()和Series.plot()中废弃了sort_columns参数(GH 47563). -
对于
DataFrame.to_stata()和read_stata()除第一个参数外的所有位置参数已被弃用,请改用关键字参数代替(GH 48128) -
在
read_csv()、read_fwf()、read_table()和read_excel()中弃用了mangle_dupe_cols参数,该参数从未被实现,将添加一个新参数,可以指定重命名模式(GH 47718) -
在
Series.astype()中不再允许dtype='datetime64'或dtype=np.datetime64,请改用“datetime64[ns]”(GH 47844)
性能改进
-
在
DataFrame.corrwith()中对列(axis=0)进行了性能改进,计算 Pearson 和 Spearman 相关性,当另一个是Series时(GH 46174) -
对一些用户定义的 DataFrame -> Series 函数,在
DataFrameGroupBy.transform()和SeriesGroupBy.transform()中进行了性能改进(GH 45387) -
在仅包含一列的情况下,对
DataFrame.duplicated()进行了性能改进(GH 45236) -
在
DataFrameGroupBy.diff()和SeriesGroupBy.diff()中进行了性能改进(GH 16706) -
当广播值用于用户定义函数时,
DataFrameGroupBy.transform()和SeriesGroupBy.transform()的性能改进(GH 45708) -
当只存在单个组时,用户定义函数的
DataFrameGroupBy.transform()和SeriesGroupBy.transform()的性能改进(GH 44977) -
在非唯一未排序索引上进行分组时,
DataFrameGroupBy.apply()和SeriesGroupBy.apply()的性能改进(GH 46527) -
在基于元组的索引的
MultiIndex中,DataFrame.loc()和Series.loc()的性能改进(GH 45681, GH 46040, GH 46330) -
当
ddof不等于一时,DataFrameGroupBy.var()和SeriesGroupBy.var()的性能改进(GH 48152) -
在
DataFrame.to_records()中的性能改进,当索引是MultiIndex时(GH 47263) -
当 MultiIndex 包含 DatetimeIndex、TimedeltaIndex 或 ExtensionDtypes 类型级别时,
MultiIndex.values的性能提升 (GH 46288) -
当左边和/或右边为空时,
merge()的性能提升 (GH 45838) -
当左边和/或右边为空时,
DataFrame.join()的性能提升 (GH 46015) -
当目标是
MultiIndex时,DataFrame.reindex()和Series.reindex()的性能提升 (GH 46235) -
在 pyarrow 支持的字符串数组中设置值时的性能提升 (GH 46400)
-
factorize()的性能提升 (GH 46109) -
在 extension dtype 标量的情况下,
DataFrame和Series构造函数的性能提升 (GH 45854) -
当提供
nrows参数时,read_excel()的性能提升 (GH 32727) -
在应用重复的 CSS 格式时,
Styler.to_excel()的性能提升 (GH 47371) -
MultiIndex.is_monotonic_increasing()的性能提升 (GH 47458) -
在
BusinessHour的str和repr中的性能提升 (GH 44764) -
当使用默认的 strftime 格式之一
"%Y-%m-%d %H:%M:%S"或"%Y-%m-%d %H:%M:%S.%f"时,日期时间数组字符串格式化的性能提升。 (GH 44764) -
在处理时间数组时,
Series.to_sql()和DataFrame.to_sql()(SQLiteTable) 的性能有所提升。 (GH 44764) -
read_sas()的性能有所提升。 (GH 47404) -
在
arrays.SparseArray的argmax和argmin中性能有所提升。 (GH 34197)
错误修复
类别
-
Categorical.view()中不接受整数类型的错误。 (GH 25464) -
当索引的类别为整数类型且索引包含
NaN值时,在CategoricalIndex.union()中出现错误,不正确地引发而不是转换为float64。 (GH 45362) -
在连接两个(或更多)无序的
CategoricalIndex变量时,在concat()中出现错误,其类别为排列组合,导致索引值不正确。 (GH 24845)
日期时间类
-
在日期时间类型且无行时,在
DataFrame.quantile()中出现错误,不正确地返回float64类型而不是保留日期时间类型。 (GH 41544) -
在处理
np.str_对象序列时,在to_datetime()中出现错误,不正确地引发。 (GH 32264) -
在传递日期时间组件作为位置参数和
tzinfo作为关键字参数时,在Timestamp构造中出现错误,不正确地引发。 (GH 31929) -
在从对象类型转换为
timedelta64[ns]类型时,在Index.astype()中出现错误,将np.datetime64("NaT")值不正确地转换为np.timedelta64("NaT")而不是引发错误。 (GH 45722) -
在传递分类列时,
SeriesGroupBy.value_counts()索引中的错误(GH 44324) -
DatetimeIndex.tz_localize()中的错误,本地化到 UTC 时未能复制底层数据(GH 46460) -
DatetimeIndex.resolution()中的错误,对于纳秒分辨率的索引,错误地返回“day”而不是“nanosecond”(GH 46903) -
在整数或浮点值和
unit="Y"或unit="M"时,Timestamp中的错误返回了略有错误的结果(GH 47266) -
在传递另一个
DatetimeArray和freq=None时,DatetimeArray构建中的错误,错误地从给定数组推断频率(GH 47296) -
在
errors=coerce时,如果行数超过 50 行,to_datetime()将引发OutOfBoundsDatetime错误(GH 45319) -
向
Series添加DateOffset时的错误,不会添加nanoseconds字段(GH 47856)
Timedelta
-
astype_nansafe()中的错误,当包含np.nan时,astype("timedelta64[ns]")操作失败(GH 45798) -
构建
Timedelta时的错误,使用np.timedelta64对象和unit,有时会悄悄地溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta错误(GH 46827) -
从大整数或浮点数使用
unit="W"构建Timedelta时的错误,悄悄地溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta错误(GH 47268)
时区
- 当传递
ZoneInfotzinfo 对象时,Timestamp构造函数引发错误(GH 46425)
Numeric
-
使用
dtype="boolean"和NA进行数组操作时存在的错误,错误地在原地更改数组(GH 45421) -
在可空类型进行算术运算时,没有
NA值的情况下,与非可空类型进行相同操作不匹配的错误(GH 48223) -
在使用
IntegerDtype除以0时,floordiv存在错误,应返回inf而不是0(GH 48223) -
在使用
dtype="boolean"进行除法、pow和mod操作时,与其np.bool_对应项不同的数组操作存在错误(GH 46063) -
在将
Series与IntegerDtype或FloatingDtype相乘时,与具有timedelta64[ns]dtype 的数组错误地引发异常(GH 45622) -
在
mean()中存在错误,可选依赖项bottleneck导致数组长度线性减少精度。已禁用bottleneck以改善mean()的损失为对数线性,但可能导致性能下降(GH 42878)
转换
-
在
DataFrame.astype()中未保留子类的错误(GH 40810) -
在从包含浮点数的列表或浮点数 ndarray-like(例如
dask.Array)构建Series时,存在错误,应像处理np.ndarray一样转换而不是引发异常(GH 40110) -
在
Float64Index.astype()中,将无符号整数 dtype 错误地转换为np.int64dtype(GH 45309) -
在从浮点 dtype 转换为无符号整数 dtype 时,
Series.astype()和DataFrame.astype()存在错误,在存在负值时未引发异常(GH 45151) -
在使用
FloatingDtype和包含可转换为浮点数的字符串值的情况下构建array()时,错误地引发异常(GH 45424) -
在比较字符串和 datetime64ns 对象时存在错误,导致
OverflowError异常(GH 45506) -
通用抽象数据类型元类中的错误导致
DataFrame.apply()和Series.apply()对内置函数type抛出异常(GH 46684) -
当索引为
MultiIndex时,DataFrame.to_records()返回不一致的 numpy 类型(GH 47263) -
对于
orient="list"或orient="index"的DataFrame.to_dict()存在错误,未返回原生类型(GH 46751) -
当应用于空的
DataFrame且axis=1时,DataFrame.apply()返回DataFrame而不是Series的错误(GH 39111") -
从不是 NumPy
ndarray的所有 NumPy 无符号整数标量组成的可迭代对象推断数据类型时出现的错误,未导致无符号整数数据类型(GH 47294) -
当 pandas 对象(例如
'Timestamp')为列名时,DataFrame.eval()存在错误(GH 44603)
字符串
-
在使用其他序列作为参数 pat 时,
str.startswith()和str.endswith()中的错误。现在引发TypeError(GH 3485) -
当字符串包含前导符号时,在
Series.str.zfill()中的错误,将‘0’填充到符号字符之前而不是之后,与标准库中的str.zfill不一致(GH 20868)
区间
-
将
np.nan设置到整数支持的数组中时,IntervalArray.__setitem__()存在错误,抛出ValueError而不是TypeError(GH 45484) -
当将 datetime64[ns, tz] 作为 dtype 字符串时,在使用
IntervalDtype时出现的 Bug(GH 46999)
索引
-
在将单个 ExtensionDtype 列上的单个行索引用于
DataFrame上时,DataFrame.iloc()中返回副本而不是基础数据的视图的 Bug(GH 45241) -
当
DataFrame具有重复列时,即使选择了唯一列,DataFrame.__getitem__()在返回副本时出现的 Bug(GH 45316, GH 41062) -
在使用的 MultiIndexes 交集完全相同时,
Series.align()中不创建具有级别并集的MultiIndex的 Bug(GH 45224) -
当将 NA 值 (
None或np.nan) 设置到具有基于整数的IntervalDtype的Series中时,错误地将其转换为对象 dtype 而不是基于浮点的IntervalDtype的 Bug(GH 45568) -
当使用
df.iloc[:, i] = values时,在将与df.iloc[:, i]具有相同 dtype 的values设置到ExtensionDtype列时出现的索引设置值的错误,错误地插入新数组而不是就地设置(GH 33457) -
在使用非整数
Index时,Series.__setitem__()中将整数键用于设置无法就地设置的值时出现的 Bug,抛出ValueError而不是转换为常见 dtype(GH 45070) -
当将值作为列表设置到
DataFrame时,DataFrame.loc()中未将None强制转换为NA的 Bug(GH 47987) -
当将不兼容的值设置为
PeriodDtype或IntervalDtypeSeries中时,Series.__setitem__()中存在错误,当使用布尔掩码索引时引发错误,但在使用等效索引器时进行强制转换;现在,这些统一进行强制转换,以及Series.mask()和Series.where()(GH 45768) -
在具有日期时间类型的多个列的情况下,
DataFrame.where()中存在错误,其下降结果与其他类型一致(GH 45837) -
在使用无 dtype 的无符号整数 dtype 和类似列表参数的情况下,
isin()中存在错误,会上升到float64(GH 46485) -
在使用多个键而不使用
MultiIndex时,Series.loc.__setitem__()和Series.loc.__getitem__()中的错误没有引发(GH 13831) -
当指定了
level但未给出MultiIndex时,Index.reindex()中存在错误,引发AssertionError;现在忽略 level (GH 35132) -
当设置值过大以至于超出
Seriesdtype 时存在错误,无法强制转换为通用类型 (GH 26049, GH 32878) -
在
loc.__setitem__()中存在错误,将range键视为基于位置而不是基于标签的键 (GH 45479) -
当使用标量键和
DataFrame作为值进行设置时,DataFrame.__setitem__()中存在错误,会将扩展数组 dtype 强制转换为对象 (GH 46896) -
当将标量设置为可空 pandas dtype 时,
Series.__setitem__()中存在错误,如果标量无法损失地转换为可空类型,则不会引发TypeError(GH 45404) -
当将包含
NA的booleandtype 值设置为时,Series.__setitem__()中存在错误,不正确地引发错误而不是转换为booleandtype (GH 45462) -
Bug in
Series.loc()在包含NA的布尔索引器引发错误时,Index不匹配(GH 46551) -
Bug in
Series.__setitem__()将NA设置��数值数据类型Series时,错误地将其上转换为对象数据类型而不是将值视为np.nan的问题(GH 44199) -
Bug in
DataFrame.loc()在将值设置为列并且右侧是字典时的问题(GH 47216) -
Bug in
Series.__setitem__()使用datetime64[ns]数据类型、全为False的布尔掩码和不兼容值时,错误地转换为object而不是保留datetime64[ns]数据类型的问题(GH 45967) -
Bug in
Index.__getitem__()在索引器来自布尔数据类型且包含NA时引发ValueError的问题(GH 45806) -
Bug in
Series.__setitem__()在扩大Series时丢失精度的问题,使用标量(GH 32346) -
Bug in
Series.mask()使用inplace=True或使用小整数数据类型的布尔掩码设置值时不正确引发错误的问题(GH 45750) -
Bug in
DataFrame.mask()使用inplace=True和ExtensionDtype列时不正确引发错误的问题(GH 45577) -
Bug in 从 DataFrame 获取带有类似日期时间值的对象数据类型行索引的列时的问题:结果 Series 现在保留了来自父 DataFrame 的确切对象数据类型索引(GH 42950)
-
Bug in
DataFrame.__getattribute__()如果列具有"string"数据类型,则引发AttributeError的问题(GH 46185) -
Bug in
DataFrame.compare()在比较扩展数组数据类型和 numpy 数据类型时返回所有NaN列的问题(GH 44014) -
Bug in
DataFrame.where()使用"boolean"掩码设置错误值的问题,numpy 数据类型错误(GH 44014) -
在对
DatetimeIndex进行索引时,使用np.str_键错误地引发异常。(GH 45580) -
在
CategoricalIndex.get_indexer()中存在的错误,当索引包含NaN值时,导致目标中存在但不在索引中的元素被映射到 NaN 元素的索引,而不是-1。(GH 45361) -
在将大整数值设置到具有
float32或float16dtype 的Series中时,错误地改变这些值,而不是强制转换为float64dtype。(GH 45844) -
在
Series.asof()和DataFrame.asof()中存在的错误,将 bool-dtype 结果错误地转换为float64dtype。(GH 16063) -
在
NDFrame.xs()、DataFrame.iterrows()、DataFrame.loc()和DataFrame.iloc()中存在的错误,不总是传播元数据。(GH 28283) -
在
DataFrame.sum()中存在的错误,如果输入包含 NaN,则 min_count 会更改 dtype。(GH 46947) -
在
IntervalTree中存在的错误导致无限递归。(GH 46658) -
在
PeriodIndex中存在的错误,在对NA进行索引时引发AttributeError,而不是将NaT放在其位置。(GH 46673) -
在
DataFrame.at()中存在的错误会允许修改多列。(GH 48296)
缺失
-
在
Series.fillna()和DataFrame.fillna()中存在的错误,downcast关键字在某些情况下未被尊重,其中不存在 NA 值。(GH 45423) -
Series.fillna()和DataFrame.fillna()中的 Bug,当值与IntervalDtype不兼容时抛出错误而不是转换为常见(通常为 object)的 dtype(GH 45796) -
Series.map()中的 Bug,如果 mapper 是dict或Series,则不遵守na_action参数(GH 47527) -
DataFrame.interpolate()中的 Bug,当列的 dtype 为 object 时,使用inplace=False时未返回副本(GH 45791) -
DataFrame.dropna()存在 Bug,允许设置不兼容参数how和thresh(GH 46575) -
DataFrame.fillna()中的 Bug,在DataFrame为单块时忽略了axis参数(GH 47713)
MultiIndex
-
DataFrame.loc()中的 Bug,在对MultiIndex进行负步长切片且非空起始/结束值时返回空结果(GH 46156) -
DataFrame.loc()中的 Bug,在对MultiIndex进行负步长切片时引发错误(GH 46156) -
DataFrame.loc()中的 Bug,当对MultiIndex进行负步长切片且切片索引级别为非整数时引发错误(GH 46156) -
在
Series.to_numpy()中存在一个错误,当提供了na_value时,无法将多级索引的 Series 转换为 numpy 数组(GH 45774) -
在
MultiIndex.equals中存在一个错误,当只有一侧具有扩展数组 dtype 时,不是可交换的(GH 46026) -
在
MultiIndex.from_tuples()中存在一个错误,无法构造空元组的索引(GH 45608)
I/O
-
在
DataFrame.to_stata()中存在一个错误,如果DataFrame包含-np.inf,则不会引发错误(GH 45350) -
在
read_excel()中存在一个错误,使用特定的skiprows回调函数会导致无限循环(GH 45585) -
在
DataFrame.info()中存在一个错误,当在空DataFrame上调用时,输出末尾的换行符会被省略(GH 45494) -
在
read_csv()中存在一个错误,对于on_bad_lines="warn"和engine="c",不会识别换行符(GH 41710) -
在
DataFrame.to_csv()中存在一个错误,不会对Float64dtype 的float_format进行尊重(GH 45991) -
在
read_csv()中存在一个错误,在所有情况下都不会尊重指定的索引列转换器(GH 40589) -
在
read_csv()中存在一个错误,即使index_col=False也将第二行解释为Index名称(GH 46569) -
在
read_parquet()中存在一个错误,当engine="pyarrow"时,如果传递了不受支持数据类型的列,则会导致部分写入磁盘(GH 44914) -
DataFrame.to_excel()和ExcelWriter在将空 DataFrame 写入.ods文件时会出现错误(GH 45793) -
对于
engine="python",read_csv()忽略不存在的标题行(GH 47400) -
当
header引用不存在的行时,read_excel()引发未受控制的IndexError(GH 43143) -
在
read_html()中,围绕<br>的元素没有用空格连接起来(GH 29528) -
当数据长度超过标题时,在
usecols中期待字符串的可调用项会导致read_csv()出现错误(GH 46997) -
Parquet 回转中
datetime64[ns]子类型的 Interval dtype 存在错误(GH 45881) -
在读取
.ods文件时,当 xml 元素之间存在换行符时,read_excel()存在错误(GH 45598) -
当
engine="fastparquet"时,read_parquet()在错误时未关闭文件(GH 46555) -
当
border关键字设置为False时,DataFrame.to_html()现在会从<table>元素中排除border属性。 -
读取某些类型的压缩 SAS7BDAT 文件时,
read_sas()存在错误(GH 35545) -
当没有给出名称时,
read_excel()在没有填充MultiIndex时存在错误(GH 47487) -
对于零行的 SAS7BDAT 文件,
read_sas()返回None而不是空 DataFrame(GH 18198) -
DataFrame.to_string()在MultiIndex中使用扩展数组时使用错误的缺失值的 bug (GH 47986) -
StataWriter中值标签始终使用默认编码写入的 bug (GH 46750) -
StataWriterUTF8中一些有效字符从变量名中被移除的 bug (GH 47276) -
DataFrame.to_excel()在写入空的 dataframe 时出现了 bug,使用MultiIndex(GH 19543) -
read_sas()在读取包含 0x40 控制字节的 RLE 压缩的 SAS7BDAT 文件时出现了 bug (GH 31243) -
read_sas()对列名进行了混淆的 bug (GH 31243) -
read_sas()在读取包含 0x00 控制字节的 RLE 压缩的 SAS7BDAT 文件时出现了 bug (GH 47099) -
read_parquet()出现了 bug,当use_nullable_dtypes=True时返回的是float64dtype 而不是可空的Float64dtype (GH 45694) -
DataFrame.to_json()出现了 bug,当使用PeriodDtype时,反序列化后使用read_json()无法循环反序列化 (GH 44720) -
read_xml()在读取包含中文字符标签的 XML 文件时出现了 bug,会引发XMLSyntaxError(GH 47902)
Period
-
Period减去PeriodArray时返回了错误的结果,出现了 bug (GH 45999) -
Period.strftime()和PeriodIndex.strftime()中的指令%l和%u给出了错误结果(GH 46252) -
当将字符串传递给微秒为 1000 的
Period时,推断出错误的freq(GH 46811) -
在使用非零纳秒且
freq="ns"的Timestamp或np.datetime64对象构造Period时存在错误,纳秒不正确截断(GH 46811) -
将
np.timedelta64("NaT", "ns")添加到具有类似时间间隔的频率的Period时存在错误,错误引发IncompatibleFrequency而不是返回NaT(GH 47196) -
在使用
PeriodDtype将整数数组添加到数组时存在错误,当dtype.freq.n > 1时结果不正确(GH 47209) -
将
Period从具有PeriodDtype的数组中减去时存在错误,操作溢出时未引发OverflowError而返回不正确结果(GH 47538)
绘图
-
DataFrame.plot.barh()存在错误,无法标记 x 轴且xlabel更新 y 轴标签(GH 45144) -
DataFrame.plot.box()存在一个错误,导致无法标记 x 轴(GH 45463) -
DataFrame.boxplot()存在错误,无法传递xlabel和ylabel(GH 45463) -
DataFrame.boxplot()存在错误,无法指定vert=False(GH 36918) -
Bug in
DataFrame.plot.scatter()导致无法指定norm(GH 45809) -
修复在未设置 ylabel 时,在
Series.plot()中显示“None”作为 ylabel 的问题(GH 46129) -
Bug in
DataFrame.plot()导致绘制季度系列时 xticks 和垂直网格放置不正确(GH 47602) -
Bug in
DataFrame.plot()导致无法为次要 y 轴设置 y 轴标签、限制和刻度(GH 47753)
Groupby/resample/rolling
-
在
DataFrame.resample()中忽略在TimedeltaIndex上的closed="right"(GH 45414) -
在输入 DataFrame 具有多列时,
DataFrameGroupBy.transform()中的 bug 在func="size"时失败(GH 27469) -
在
func="size"的情况下,DataFrameGroupBy.size()和DataFrameGroupBy.transform()中的 bug 会在axis=1时产生不正确的结果(GH 45715) -
在
ExponentialMovingWindow.mean()中的 bug,当axis=1且engine='numba'时,当DataFrame的列数多于行数时(GH 46086) -
使用
engine="numba"时的 bug 会在修改engine_kwargs时返回相同的 jit 函数(GH 46086) -
当
axis=1且func为"first"或"last"时,DataFrameGroupBy.transform()会失败 (GH 45986) -
DataFrameGroupBy.cumsum()中的错误,当skipna=False时会导致结果不正确 (GH 46216) -
DataFrameGroupBy.sum()、SeriesGroupBy.sum()、DataFrameGroupBy.prod()、SeriesGroupBy.prod和DataFrameGroupBy.cumsum()、以及SeriesGroupBy.cumsum()中的错误,当整数类型丢失精度时 (GH 37493) -
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()中的错误,当timedelta64[ns]类型无法识别NaT为 null 值时 (GH 46216) -
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()中的错误,当整数类型导致总和大于 dtype 的最大值时溢出 (GH 37493) -
Bug in
DataFrameGroupBy.cummin(),SeriesGroupBy.cummin(),DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()在可空数据类型时不正确地改变原始数据(GH 46220) -
Bug in
DataFrame.groupby()当None出现在MultiIndex的第一级时会引发错误(GH 47348) -
Bug in
DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()在int64数据类型中,最小可能的 int64 值为首位时出现问题(GH 46382) -
Bug in
DataFrameGroupBy.cumprod()和SeriesGroupBy.cumprod()在skipna=False的情况下,NaN会影响不同列的计算(GH 48064) -
Bug in
DataFrameGroupBy.max()和SeriesGroupBy.max()在空分组和uint64数据类型时不正确地引发RuntimeError(GH 46408) -
在
DataFrameGroupBy.apply()和SeriesGroupBy.apply()中存在的错误,当func为字符串且提供了 args 或 kwargs 时会失败(GH 46479)。 -
在
SeriesGroupBy.apply()中存在的错误,当存在唯一分组时,其结果会被错误地命名(GH 46369)。 -
在
Rolling.sum()和Rolling.mean()中存在的错误,当窗口值相同时会得到错误的结果(GH 42064,GH 46431)。 -
在
Rolling.var()和Rolling.std()中存在的错误,当窗口值相同时会得到非零结果(GH 42064)。 -
在
Rolling.skew()和Rolling.kurt()中存在的错误,当窗口值相同时会得到 NaN(GH 30993)。 -
在
Rolling.var()中存在的错误,当窗口大小大于数据大小时,计算加权方差会导致段错误(GH 46760)。 -
在
Grouper.__repr__()中存在的错误,dropna未被包含。现在已经包含了(GH 46754)。 -
在
DataFrame.rolling()中存在的错误,当 center=True,axis=1 并且指定了 win_type 时会产生 ValueError(GH 46135)。 -
对于空数据集,
DataFrameGroupBy.describe()和SeriesGroupBy.describe()生成的结果不一致(GH 41575)。 -
DataFrame.resample()方法在使用on参数时存在缺陷,会尝试对提供的列进行聚合(GH 47079)。 -
当输入的 DataFrame/Series 在
MultiIndex中具有 NaN 值时,DataFrame.groupby()和Series.groupby()在不尊重dropna=False时存在缺陷(GH 46783)。 -
当从缺少重新采样键的键列表中获取结果时,
DataFrameGroupBy.resample()存在缺陷,会引发KeyError(GH 47362)。 -
当 DataFrame 为空时,
DataFrame.groupby()在进行转换(例如 fillna)时会丢失索引列(GH 47787)。 -
当
dropna=False和sort=False时,DataFrame.groupby()和Series.groupby()中的任何空组会被放置在末尾而不是按照它们被遇到的顺序(GH 46584)。
重塑
-
当一个具有整数 dtype 的
Series和另一个具有整数类别的CategoricalDtype并且包含NaN值的情况下,concat()存在缺陷,将其转换为对象 dtype 而不是float64(GH 45359)。 -
在选择对象和分类 dtype 而不是字符串时存在缺陷,
get_dummies()(GH 44965)。 -
在
DataFrame.align()中存在 bug,当将MultiIndex与另一个MultiIndex的Series对齐时会出错(GH 46001) -
在使用
IntegerDtype或FloatingDtype数组进行连接时存在 bug,结果 dtype 不会反映非空 dtypes 的行为(GH 46379) -
在
concat()中存在 bug,当join="outer"且sort=True时,会丢失列的 dtype(GH 47329) -
在
concat()中存在 bug,当包含None时,不会对列名进行排序(GH 47331) -
在
concat()中存在 bug,具有相同键的连接导致在索引MultiIndex时出错(GH 46519) -
在
pivot_table()中存在 bug,当dropna=True且聚合列具有扩展数组 dtype 时,会引发TypeError(GH 47477) -
在
merge()中存在 bug,当在 ssl 库中使用FIPS模式时,使用how="cross"会引发错误(GH 48024) -
在
DataFrame.join()中存在 bug,使用后缀连接具有重复列名的 DataFrame 列表时会出错(GH 46396) -
在
DataFrame.pivot_table()中存在 bug,使用sort=False会导致索引排序(GH 17041) -
在
concat()中存在 bug,当axis=1且sort=False时,结果的索引是Int64Index而不是RangeIndex(GH 46675) -
在
wide_to_long()中存在 bug,当列中缺少stubnames且i包含字符串 dtype 列时,会引发错误(GH 46044) -
在
DataFrame.join()中的一个错误,使用分类索引导致意外重新排序。(GH 47812)
稀疏
-
在
Series.where()和DataFrame.where()中的一个错误,当使用SparseDtype时未能保留数组的fill_value。(GH 45691) -
在
SparseArray.unique()中的一个错误,无法保留原始元素的顺序。(GH 47809)
扩展数组
- 在
IntegerArray.searchsorted()和FloatingArray.searchsorted()上的一个错误,在操作np.nan时返回不一致的结果。(GH 45255)
样式
-
尝试将样式函数应用于空 DataFrame 子集时的错误。(GH 45313)
-
在
xlsxwriter引擎中,当未提供边框样式而提供了边框颜色时,导致TypeError的CSSToExcelConverter中的一个错误。(GH 42276) -
在
Styler.set_sticky()中的一个错误,导致在暗模式下白色文本显示在白色背景上。(GH 46984) -
在
Styler.to_latex()中的一个错误导致当clines="all;data"且DataFrame没有行时引发UnboundLocalError。(GH 47203) -
当使用
xlsxwriter引擎时,在Styler.to_excel()中的一个错误,当使用vertical-align: middle;时引发错误。(GH 30107) -
在带有布尔列标签的 DataFrame 应用样式时的错误。(GH 47838)
元数据
其他
- 在
assert_index_equal()中的一个错误,当names=True且check_order=False时未检查名称。(GH 47328)
分类
-
在
Categorical.view()中的一个错误,不接受整数类型。(GH 25464) -
在
CategoricalIndex.union()中的一个错误,当索引的类别为整数类型且索引包含NaN值时,错误地引发而不是转换为float64。(GH 45362) -
在连接两个(或更多)无序
CategoricalIndex变量时,在concat()中,其类别为排列组合,产生了不正确的索引值 (GH 24845)
类似日期时间的 Bug
-
在具有类似日期时间的 dtypes 且没有行的
DataFrame.quantile()中,不正确地返回float64dtype 而不是保留类似日期时间的 dtype(GH 41544) -
在
to_datetime()中,使用np.str_对象序列时不正确地提升错误(GH 32264) -
在将日期时间组件作为位置参数传递并将
tzinfo作为关键字参数时,构造Timestamp时出现错误提升 (GH 31929) -
在从对象 dtype 转换为
timedelta64[ns]dtype 时,在Index.astype()中,不正确地将np.datetime64("NaT")值转换为np.timedelta64("NaT")而不是提升错误(GH 45722) -
当传递分类列时,在
SeriesGroupBy.value_counts()索引中存在问题 (GH 44324) -
在将本地化到 UTC 的
DatetimeIndex.tz_localize()中,未能复制基础数据导致失败 (GH 46460) -
在
DatetimeIndex.resolution()中,不正确地返回“day”而不是纳秒分辨率索引的“nanosecond”(GH 46903) -
在使用整数或浮点值以及
unit="Y"或unit="M"时,Timestamp存在问题,结果略有偏差(GH 47266) -
当传递另一个
DatetimeArray且freq=None时,DatetimeArray构造中的 Bug 会错误地从给定数组中推断频率 (GH 47296) -
当存在超过 50 行时,
to_datetime()中的 Bug 会抛出OutOfBoundsDatetime,即使errors=coerce(GH 45319) -
将
DateOffset添加到Series时,Bug 不会添加nanoseconds字段 (GH 47856)
时间差
-
astype_nansafe()中的 Bug 在包含np.nan时转换为timedelta64[ns]会失败 (GH 45798) -
使用
np.timedelta64对象和unit构造Timedelta时,Bug 有时会静默溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta(GH 46827) -
当使用
unit="W"从大整数或浮点数构造Timedelta时,Bug 会静默溢出并返回不正确的结果,而不是引发OutOfBoundsTimedelta(GH 47268)
时区
- 当传递一个
ZoneInfotzinfo 对象时,Timestamp构造函数会引发 Bug (GH 46425)
数值
-
使用
dtype="boolean"和NA的数组类进行操作时的 Bug 会错误地改变数组本身 (GH 45421) -
在没有
NA值的可空类型的算术操作中存在 Bug,与非可空类型的相同操作不匹配 (GH 48223) -
当除以
IntegerDtype0时,floordiv中的 Bug 会返回0而不是inf(GH 48223) -
在具有
dtype="boolean"的数组类上进行除法、pow和mod操作的 Bug 不像其np.bool_对应物一样 (GH 46063) -
在将具有
IntegerDtype或FloatingDtype的Series与具有timedelta64[ns]dtype 的数组类相乘时,存在错误地提升。(GH 45622) -
在可选依赖
bottleneck导致精度损失与数组长度线性相关的mean()中存在错误。已禁用mean()中的bottleneck,将损失改进为对数线性,但可能导致性能降低。(GH 42878)
转换
-
在
DataFrame.astype()中不存在保留子类。(GH 40810) -
从包含浮点数的列表或浮点数
ndarray(例如dask.Array)构造Series时出现错误,整数 dtype 应该像处理np.ndarray一样转换,而不是提升。(GH 40110) -
在将
Float64Index.astype()转换为无符号整数 dtype 时,错误地将其转换为np.int64dtype。(GH 45309) -
在从浮点 dtype 转换为无符号整数 dtype 时,
Series.astype()和DataFrame.astype()中存在错误,在存在负值的情况下未能提升。(GH 45151) -
在使用
FloatingDtype和包含可转换为浮点数的值的情况下,array()中存在错误,错误地提升。(GH 45424) -
当比较字符串和
datetime64ns对象时出现错误,导致OverflowError异常。(GH 45506) -
在通用抽象 dtype 的元类中存在错误,导致内置函数
type在DataFrame.apply()和Series.apply()中抛出异常。(GH 46684) -
在
DataFrame.to_records()中存在错误,如果索引是MultiIndex,则返回不一致的 numpy 类型。(GH 47263) -
DataFrame.to_dict()中的错误,对于orient="list"或orient="index",未返回原生类型(GH 46751)。 -
DataFrame.apply()中的错误,在应用于空的DataFrame且axis=1时,返回DataFrame而不是Series(GH 39111)。 -
当推断来自不是全部为 NumPy 无符号整数标量的 NumPy
ndarray的数据类型时,出现错误,未能得到无符号整数 dtype(GH 47294)。 -
DataFrame.eval()中的错误,当 pandas 对象(例如'Timestamp')作为列名时(GH 44603)。
字符串
-
使用其他序列作为参数 pat 时,
str.startswith()和str.endswith()中的错误。现在会引发TypeError(GH 3485)。 -
Series.str.zfill()中的错误,当字符串包含前导符号时,填充'0'到符号字符之前而不是之后,与标准库中的str.zfill不符(GH 20868)。
区间
-
IntervalArray.__setitem__()中的错误,当将np.nan设置到整数支持的数组中时,引发ValueError而不是TypeError(GH 45484)。 -
IntervalDtype中的错误,当使用 datetime64[ns, tz]作为 dtype 字符串时(GH 46999)。
索引
-
DataFrame.iloc()中的错误,当在一个包含单个 ExtensionDtype 列的DataFrame上索引单个行时,会得到底层数据的副本而不是视图(GH 45241)。 -
当
DataFrame具有重复列时,DataFrame.__getitem__()返回副本,即使选择了唯一列也是如此,存在一个错误(GH 45316, GH 41062) -
当两个 MultiIndexes 交集相同时,
Series.align()不会创建具有级别联合的MultiIndex,存在一个错误(GH 45224) -
在将 NA 值(
None或np.nan)设置到基于整数的IntervalDtype的Series中时,错误地将其转换为对象 dtype 而不是基于浮点数的IntervalDtype(GH 45568) -
在使用
df.iloc[:, i] = values将值设置到ExtensionDtype列中时,如果values与df.iloc[:, i]具有相同的 dtype,则错误地插入新数组而不是原地设置(GH 33457) -
在使用整数键设置无法原地设置值时,
Series.__setitem__()中存在一个与非整数Index相关的错误,会引发ValueError而不是转换为通用 dtype(GH 45070) -
在将值设置为列表插入
DataFrame时,DataFrame.loc()中存在一个错误,未将None转换为NA(GH 47987) -
在将不兼容值设置到
PeriodDtype或IntervalDtypeSeries中时,Series.__setitem__()存在一个错误,当使用布尔掩码进行索引时引发错误,但使用其他等效索引器进行索引时进行强制转换;现在这些都会一致地进行强制转换,以及Series.mask()和Series.where()(GH 45768) -
在具有类似日期时间的 dtype 的多列的
DataFrame.where()中存在一个错误,无法将结果向下转换为与其他 dtype 一致的结果(GH 45837) -
在使用无符号整数 dtype 和类似列表的参数而不带有 dtype 的情况下,
isin()的错误将升级为float64(GH 46485)。 -
当使用多个键而不使用
MultiIndex时,Series.loc.__setitem__()和Series.loc.__getitem__()不会引发错误(GH 13831)。 -
在指定了
level但未给出MultiIndex时,Index.reindex()引发AssertionError的错误;现在忽略 level(GH 35132)。 -
当将
range键视为基于位置而不是基于标签时,loc.__setitem__()中出现错误(GH 45479)。 -
当使用标量键和
DataFrame作为值进行设置时,DataFrame.__setitem__()将扩展数组 dtype 转换为对象(GH 46896)。 -
当将标量设置为可为空的 pandas dtype 时,如果标量无法无损地转换为可为空的类型,则不会引发
TypeError,出现Series.__setitem__()中的错误(GH 45404)。 -
当设置包含
NA的booleandtype 值时,Series.__setitem__()出现错误,而不是将值转换为booleandtype(GH 45462)。 -
当包含
NA的布尔索引器与不匹配的Index一起使用时,Series.loc()出现错误(GH 46551)。 -
当将
NA设置为数值类型Series时,会将其错误地上升为对象 dtype,而不是将该值视为np.nan(GH 44199)。 -
当将值设置为列并且右侧是字典时,
DataFrame.loc()中的错误(GH 47216)。 -
使用
datetime64[ns]dtype、全False布尔 mask 和不兼容值时,Series.__setitem__()错误地将值转换为object,而不是保留datetime64[ns]dtype(GH 45967) -
当索引器来自布尔 dtype 且带有
NA时,Index.__getitem__()引发ValueError的错误(GH 45806) -
在扩大
Series时,Series.__setitem__()失去了精度的错误(GH 32346) -
使用
inplace=True或使用小整数 dtype 的布尔 mask 设置值时,Series.mask()错误地引发问题(GH 45750) -
Bug in
DataFrame.mask()使用inplace=True和ExtensionDtype列时,错误地引发了问题(GH 45577) -
在具有类似 datetime 的值的对象-dtype 行索引的 DataFrame 中获取列时的错误:结果 Series 现在保留了父 DataFrame 的精确对象-dtype 索引(GH 42950)
-
在列具有
"string"dtype 时,DataFrame.__getattribute__()引发AttributeError的错误(GH 46185) -
在比较扩展数组 dtype 和 numpy dtype 时,
DataFrame.compare()返回所有NaN列的错误(GH 44014) -
使用
"boolean"mask 设置 numpy dtype 的错误值时,DataFrame.where()设置错误的值(GH 44014) -
在具有
np.str_键的DatetimeIndex上进行索引时的错误引发(GH 45580) -
当索引包含
NaN值时,CategoricalIndex.get_indexer()中的错误,导致了目标中存在但不在索引中的元素被映射到 NaN 元素的索引位置,而不是 -1(GH 45361) -
使用
float32或float16dtype 将大整数值设置到Series中时,错误地改变了这些值,而不是强制转换为float64dtype(GH 45844) -
Series.asof()和DataFrame.asof()中的 bug 将 bool-dtype 的结果错误地转换为float64dtype (GH 16063) -
NDFrame.xs(),DataFrame.iterrows(),DataFrame.loc()和DataFrame.iloc()中的 bug 不始终传播元数据 (GH 28283) -
DataFrame.sum()中的 bug min_count 如果输入包含 NaN,则更改 dtype (GH 46947) -
IntervalTree中的 bug 导致无限递归。 (GH 46658) -
在
PeriodIndex中,当在NA上索引时引发AttributeError的 bug,而不是将NaT放在其位置。 (GH 46673) -
DataFrame.at()中的 bug 允许修改多个列 (GH 48296)
缺失
-
Series.fillna()和DataFrame.fillna()在某些情况下未尊重downcast关键字,即使没有 NA 值存在也会出现问题 (GH 45423) -
Series.fillna()和DataFrame.fillna()在使用IntervalDtype时存在 bug,不兼容的值引发而不是转换为通用(通常是对象)dtype (GH 45796) -
Series.map()中的 bug 如果 mapper 是一个dict或Series,则不尊重na_action参数 (GH 47527) -
DataFrame.interpolate()中的错误,对象类型列不返回inplace=False的副本(GH 45791) -
DataFrame.dropna()中的错误允许设置不兼容的how和thresh参数(GH 46575) -
DataFrame.fillna()中的错误,在DataFrame为单个块时忽略了axis(GH 47713)
MultiIndex
-
DataFrame.loc()在对具有负步长和非空起始/停止值的MultiIndex进行切片时返回空结果(GH 46156) -
DataFrame.loc()在对具有负步长的MultiIndex进行切片时出错,步长不为-1(GH 46156) -
DataFrame.loc()在对具有负步长的MultiIndex进行切片时出错,并且对非整数标记的索引级别进行切片(GH 46156) -
Series.to_numpy()中的错误,当提供na_value时,多索引 Series 无法转换为 numpy 数组(GH 45774) -
MultiIndex.equals中的错误,当只有一侧具有扩展数组数据类型时不是可交换的(GH 46026) -
MultiIndex.from_tuples()中的错误,无法构建空元组的索引(GH 45608)
I/O
-
DataFrame.to_stata()中的错误,如果DataFrame包含-np.inf,则不会引发错误(GH 45350) -
在某些
skiprows可调用函数的情况下,read_excel()中存在的 Bug 导致无限循环(GH 45585) -
当在空的
DataFrame上调用时,DataFrame.info()存在的 Bug 会省略输出末尾的换行符(GH 45494) -
对于
engine="c"和on_bad_lines="warn",read_csv()中存在的 Bug 未能识别换行符(GH 41710) -
对于
Float64数据类型,DataFrame.to_csv()存在的 Bug 未能尊重float_format(GH 45991) -
在某些情况下,
read_csv()中存在的 Bug 未能尊重指定的索引列转换器(GH 40589) -
即使
index_col=False,read_csv()中存在的 Bug 也会将第二行解释为Index名称(GH 46569) -
在使用
engine="pyarrow"时,read_parquet()存在的 Bug 导致当传递不支持的数据类型的列时,会部分写入磁盘(GH 44914) -
将空 DataFrame 写入
.ods文件时,DataFrame.to_excel()和ExcelWriter存在的 Bug 会引发错误(GH 45793) -
在
engine="python"时,read_csv()存在的 Bug 忽略了不存在的标题行(GH 47400) -
当
header引用不存在的行时,read_excel()中存在的 Bug 会引发未受控制的IndexError(GH 43143) -
在没有空格的情况下连接
<br>周围元素的 Bug 导致read_html()出现问题(GH 29528) -
在
read_csv()中,当数据比标题更长时,导致在usecols中期望字符串的可调用项出现问题(GH 46997) -
在 Parquet 往返中存在错误,对于带有
datetime64[ns]子类型的 Interval dtype(GH 45881) -
在
read_excel()中,读取带有 xml 元素之间换行的.ods文件存在错误(GH 45598) -
在
read_parquet()中,当engine="fastparquet"时,文件在错误时未关闭(GH 46555) -
DataFrame.to_html()现在在border关键字设置为False时,从<table>元素中排除border属性。 -
在
read_sas()中,对于某些类型的压缩 SAS7BDAT 文件存在错误(GH 35545) -
在
read_excel()中,当未给出名称时,不会向前填充MultiIndex(GH 47487) -
在
read_sas()中,对于具有零行的 SAS7BDAT 文件,返回None而不是空数据框存在错误(GH 18198) -
在
DataFrame.to_string()中存在错误,使用了扩展数组中的错误缺失值在MultiIndex中(GH 47986) -
在
StataWriter中存在错误,值标签始终使用默认编码写入(GH 46750) -
在
StataWriterUTF8中存在错误,一些有效字符从变量名中删除了(GH 47276) -
在
DataFrame.to_excel()中,当使用MultiIndex写入空数据框时存在错误(GH 19543) -
在包含 0x40 控制字节的 RLE 压缩 SAS7BDAT 文件中,
read_sas()存在 bug(GH 31243) -
在
read_sas()中存在 bug,导致列名混乱(GH 31243) -
在包含 0x00 控制字节的 RLE 压缩 SAS7BDAT 文件中,
read_sas()存在 bug(GH 47099) -
在使用
use_nullable_dtypes=True时,read_parquet()存在 bug,返回float64类型而不是可空的Float64类型(GH 45694) -
在
DataFrame.to_json()中存在 bug,当使用read_json()读回时,PeriodDtype无法进行序列化往返(GH 44720) -
在读取包含中文字符标签的 XML 文件时,
read_xml()存在 bug,会引发XMLSyntaxError(GH 47902)
Period
-
从
Period减去PeriodArray存在 bug,导致返回错误结果(GH 45999) -
在
Period.strftime()和PeriodIndex.strftime()中,指令%l和%u会产生错误结果(GH 46252) -
当将微秒传递给
Period时,推断出错误的freq存在 bug,这些微秒是 1000 的倍数(GH 46811) -
从
Timestamp或np.datetime64对象构造Period时,当纳秒不为零且freq="ns"时,会错误地截断纳秒(GH 46811) -
在将
np.timedelta64("NaT", "ns")添加到具有类似于 timedelta 的频率的Period时,出现错误的 bug,错误地引发IncompatibleFrequency而不是返回NaT(GH 47196) -
在使用
PeriodDtype将整数数组添加到具有 dtype.freq.n > 1 的数组时出现错误的 bug (GH 47209) -
在从具有
PeriodDtype的数组中减去一个Period时出现错误的 bug,当操作溢出时没有引发OverflowError,而是返回错误的结果 (GH 47538)
绘图
-
Bug in
DataFrame.plot.barh(),导致无法为 x 轴和xlabel更新 y 轴标签 (GH 45144) -
Bug in
DataFrame.plot.box(),导致无法标记 x 轴 (GH 45463) -
Bug in
DataFrame.boxplot(),导致无法传递xlabel和ylabel(GH 45463) -
Bug in
DataFrame.boxplot(),导致无法指定vert=False(GH 36918) -
Bug in
DataFrame.plot.scatter(),导致无法指定norm(GH 45809) -
在
Series.plot()中修复了当未设置 y 轴标签时将“None”显示为 ylabel 的问题 (GH 46129) -
Bug in
DataFrame.plot(),导致在绘制季度系列时 xticks 和垂直网格放置不当 (GH 47602) -
Bug in
DataFrame.plot(),导致无法为辅助 y 轴设置 y 轴标签、限制和刻度(GH 47753)
Groupby/resample/rolling
-
在
DataFrame.resample()中忽略TimedeltaIndex上的closed="right"(GH 45414) -
在
DataFrameGroupBy.transform()中当func="size"且输入 DataFrame 有多列时存在错误(GH 27469) -
在
DataFrameGroupBy.size()和DataFrameGroupBy.transform()中当func="size"且axis=1时产生不正确的结果(GH 45715) -
在
ExponentialMovingWindow.mean()中当axis=1且engine='numba'时,当DataFrame的列数多于行数时存在错误(GH 46086) -
当使用
engine="numba"时修改engine_kwargs会返回相同的编译函数存在错误(GH 46086) -
在
DataFrameGroupBy.transform()中当axis=1且func为"first"或"last"时存在错误(GH 45986) -
在
DataFrameGroupBy.cumsum()中当skipna=False时返回不正确的结果(GH 46216) -
DataFrameGroupBy.sum()、SeriesGroupBy.sum()、DataFrameGroupBy.prod()、SeriesGroupBy.prod, :meth:().DataFrameGroupBy.cumsum和SeriesGroupBy.cumsum()` 存在整数类型的漏洞,导致精度丢失 (GH 37493) -
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()存在漏洞,无法将timedelta64[ns]类型的NaT识别为 null 值 (GH 46216) -
DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()存在整数类型的漏洞,当总和大于 dtype 的最大值时会发生溢出 (GH 37493) -
DataFrameGroupBy.cummin()、SeriesGroupBy.cummin()、DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()存在空类型的漏洞,错误地更改了原始数据 (GH 46220) -
当
None在MultiIndex的第一层时,DataFrame.groupby()引发错误(GH 47348) -
具有
int64数据类型且具有最小可能 int64 的首个值时,DataFrameGroupBy.cummax()和SeriesGroupBy.cummax()中存在错误(GH 46382) -
在具有
skipna=False的不同列中,DataFrameGroupBy.cumprod()和SeriesGroupBy.cumprod()中的NaN影响计算(GH 48064) -
Bug in
DataFrameGroupBy.max()和SeriesGroupBy.max()在空分组和uint64数据类型情况下错误地引发RuntimeError(GH 46408) -
当
func是字符串且提供了 args 或 kwargs 时,DataFrameGroupBy.apply()和SeriesGroupBy.apply()存在错误(GH 46479) -
当存在唯一分组时,
SeriesGroupBy.apply()中存在错误的命名其结果(GH 46369) -
Rolling.sum()和Rolling.mean()中的 Bug 在窗口值相同的情况下会返回不正确的结果(GH 42064, GH 46431) -
Rolling.var()和Rolling.std()中的 Bug 在窗口值相同的情况下会返回非零结果(GH 42064) -
Rolling.skew()和Rolling.kurt()中的 Bug 在窗口值相同的情况下会返回 NaN(GH 30993) -
Rolling.var()中的 Bug 在窗口大小大于数据大小时计算加权方差会导致段错误(GH 46760) -
Grouper.__repr__()中的 Bug 中未包含dropna。现在已包含(GH 46754) -
DataFrame.rolling()中的 Bug 在 center=True、axis=1 和指定 win_type 时会返回 ValueError(GH 46135) -
DataFrameGroupBy.describe()和SeriesGroupBy.describe()中的 Bug 在空数据集上产生不一致的结果(GH 41575) -
DataFrame.resample()中的 Bug 在使用on时会尝试聚合提供的列(GH 47079) -
在
DataFrame.groupby()和Series.groupby()中,当输入的 DataFrame/Series 在MultiIndex中具有 NaN 值时,不会遵守dropna=False(GH 46783)。 -
在
DataFrameGroupBy.resample()中,当从一个遗漏了重新取样键的键列表中获取结果时,会引发KeyError(GH 47362)。 -
在
DataFrame.groupby()中,当 DataFrame 为空时,对于像 fillna 这样的变换会丢失索引列(GH 47787)。 -
在
DataFrame.groupby()和Series.groupby()中,当dropna=False和sort=False时,任何空组都会被放在最后,而不是按照它们遇到的顺序(GH 46584)。
重塑
-
在
concat()中,一个带有整数 dtype 的Series与另一个带有整数类别并包含NaN值的CategoricalDtype之间的连接,将其转换为对象 dtype 而不是float64出现错误(GH 45359)。 -
在
get_dummies()中,选择对象和分类 dtypes,但不选择字符串出现错误(GH 44965)。 -
在
DataFrame.align()对齐时,将一个带有另一个MultiIndex的Series与另一个MultiIndex对齐时出现错误(GH 46001)。 -
在具有
IntegerDtype或FloatingDtype数组的连接中,结果 dtype 不会反映非可空 dtype 的行为(GH 46379)。 -
当
join="outer"且sort=True时,concat()丢失列的 dtype(GH 47329) -
当包含
None时,concat()未对列名进行排序(GH 47331) -
在
concat()中存在相同键值的错误导致对MultiIndex进行索引时出错(GH 46519) -
当
dropna=True且聚合列具有扩展数组 dtype 时,在pivot_table()中引发TypeError(GH 47477) -
当在 ssl 库中使用
FIPS模式时,使用how="cross"时,merge()引发错误(GH 48024) -
当使用后缀连接具有重复列名的 DataFrame 时,在
DataFrame.join()中出现错误(GH 46396) -
在具有
sort=False的DataFrame.pivot_table()中出现错误,导致索引排序(GH 17041) -
当
axis=1且sort=False时,concat()中的结果索引为Int64Index而不是RangeIndex(GH 46675) -
当
stubnames在列中缺失且i包含字符串 dtype 列时,在wide_to_long()中引发错误(GH 46044) -
使用分类索引时,在
DataFrame.join()中出现意外的重新排序(GH 47812)
稀疏
-
在具有
SparseDtype的Series.where()和DataFrame.where()中出现错误,未能保留数组的fill_value(GH 45691) -
SparseArray.unique()中的缺陷未能保持原始元素顺序(GH 47809)
ExtensionArray
- 当对
np.nan进行操作时,IntegerArray.searchsorted()和FloatingArray.searchsorted()返回不一致的结果存在缺陷(GH 45255)
Styler
-
当尝试将样式函数应用于空数据框子集时存在缺陷(GH 45313)
-
CSSToExcelConverter存在缺陷,当为xlsxwriter引擎提供边框颜色而未提供边框样式时导致TypeError(GH 42276) -
Styler.set_sticky()存在缺陷,导致在暗模式下白色文本显示在白色背景上(GH 46984) -
在
Styler.to_latex()中存在缺陷,当clines="all;data"且DataFrame没有行时引发UnboundLocalError(GH 47203) -
使用
xlsxwriter引擎时,在Styler.to_excel()中使用vertical-align: middle;存在缺陷(GH 30107) -
应用样式到具有布尔列标签的数据框时存在缺陷(GH 47838)
Metadata
其他
- 当
names=True和check_order=False时,assert_index_equal()存在缺陷,未检查名称(GH 47328)
贡献者
本版本共有 271 人贡献了补丁。以“+”标记的人是首次贡献补丁的贡献者。
-
Aadharsh Acharya +
-
Aadharsh-Acharya +
-
Aadhi Manivannan +
-
Adam Bowden
-
Aditya Agarwal +
-
Ahmed Ibrahim +
-
Alastair Porter +
-
Alex Povel +
-
Alex-Blade
-
Alexandra Sciocchetti +
-
AlonMenczer +
-
Andras Deak +
-
Andrew Hawyrluk
-
Andy Grigg +
-
Aneta Kahleová +
-
Anthony Givans +
-
Anton Shevtsov +
-
B. J. Potter +
-
BarkotBeyene +
-
Ben Beasley +
-
Ben Wozniak +
-
Bernhard Wagner +
-
Boris Rumyantsev
-
Brian Gollop +
-
CCXXXI +
-
Chandrasekaran Anirudh Bhardwaj +
-
Charles Blackmon-Luca +
-
Chris Moradi +
-
ChrisAlbertsen +
-
Compro Prasad +
-
DaPy15
-
Damian Barabonkov +
-
Daniel I +
-
Daniel Isaac +
-
Daniel Schmidt
-
Danil Iashchenko +
-
Dare Adewumi
-
Dennis Chukwunta +
-
Dennis J. Gray +
-
Derek Sharp +
-
Dhruv Samdani +
-
Dimitra Karadima +
-
Dmitry Savostyanov +
-
Dmytro Litvinov +
-
Do Young Kim +
-
Dries Schaumont +
-
Edward Huang +
-
Eirik +
-
Ekaterina +
-
Eli Dourado +
-
Ezra Brauner +
-
Fabian Gabel +
-
FactorizeD +
-
Fangchen Li
-
Francesco Romandini +
-
Greg Gandenberger +
-
Guo Ci +
-
Hiroaki Ogasawara
-
Hood Chatham +
-
Ian Alexander Joiner +
-
Irv Lustig
-
Ivan Ng +
-
JHM Darbyshire
-
JHM Darbyshire (MBP)
-
JHM Darbyshire (iMac)
-
JMBurley
-
Jack Goldsmith +
-
James Freeman +
-
James Lamb
-
James Moro +
-
Janosh Riebesell
-
Jarrod Millman
-
Jason Jia +
-
Jeff Reback
-
Jeremy Tuloup +
-
Johannes Mueller
-
John Bencina +
-
John Mantios +
-
John Zangwill
-
Jon Bramley +
-
Jonas Haag
-
Jordan Hicks
-
Joris Van den Bossche
-
Jose Ortiz +
-
JosephParampathu +
-
José Duarte
-
Julian Steger +
-
Kai Priester +
-
Kapil E. Iyer +
-
Karthik Velayutham +
-
Kashif Khan
-
Kazuki Igeta +
-
Kevin Jan Anker +
-
Kevin Sheppard
-
Khor Chean Wei
-
Kian Eliasi
-
Kian S +
-
Kim, KwonHyun +
-
Kinza-Raza +
-
Konjeti Maruthi +
-
Leonardus Chen
-
Linxiao Francis Cong +
-
Loïc Estève
-
LucasG0 +
-
Lucy Jiménez +
-
Luis Pinto
-
Luke Manley
-
Marc Garcia
-
Marco Edward Gorelli
-
Marco Gorelli
-
MarcoGorelli
-
Margarete Dippel +
-
Mariam-ke +
-
Martin Fleischmann
-
Marvin John Walter +
-
Marvin Walter +
-
Mateusz
-
Matilda M +
-
Matthew Roeschke
-
Matthias Bussonnier
-
MeeseeksMachine
-
Mehgarg +
-
Melissa Weber Mendonça +
-
Michael Milton +
-
Michael Wang
-
Mike McCarty +
-
Miloni Atal +
-
Mitlasóczki Bence +
-
Moritz Schreiber +
-
Morten Canth Hels +
-
Nick Crews +
-
NickFillot +
-
Nicolas Hug +
-
Nima Sarang
-
Noa Tamir +
-
Pandas 开发团队
-
Parfait Gasana
-
Parthi +
-
Partho +
-
Patrick Hoefler
-
Peter
-
Peter Hawkins +
-
Philipp A
-
Philipp Schaefer +
-
Pierrot +
-
Pratik Patel +
-
Prithvijit
-
Purna Chandra Mansingh +
-
Radoslaw Lemiec +
-
RaphSku +
-
Reinert Huseby Karlsen +
-
Richard Shadrach
-
Richard Shadrach +
-
Robbie Palmer
-
Robert de Vries
-
Roger +
-
Roger Murray +
-
Ruizhe Deng +
-
SELEE +
-
Sachin Yadav +
-
Saiwing Yeung +
-
Sam Rao +
-
Sandro Casagrande +
-
Sebastiaan Vermeulen +
-
Shaghayegh +
-
Shantanu +
-
Shashank Shet +
-
Shawn Zhong +
-
Shuangchi He +
-
Simon Hawkins
-
Simon Knott +
-
Solomon Song +
-
Somtochi Umeh +
-
Stefan Krawczyk +
-
Stefanie Molin
-
Steffen Rehberg
-
Steven Bamford +
-
Steven Rotondo +
-
Steven Schaerer
-
Sylvain MARIE +
-
Sylvain Marié
-
Tarun Raghunandan Kaushik +
-
Taylor Packard +
-
Terji Petersen
-
Thierry Moisan
-
Thomas Grainger
-
Thomas Hunter +
-
Thomas Li
-
Tim McFarland +
-
Tim Swast
-
Tim Yang +
-
Tobias Pitters
-
Tom Aarsen +
-
Tom Augspurger
-
Torsten Wörtwein
-
TraverseTowner +
-
Tyler Reddy
-
Valentin Iovene
-
Varun Sharma +
-
Vasily Litvinov
-
Venaturum
-
Vinicius Akira Imaizumi +
-
Vladimir Fokow +
-
Wenjun Si
-
Will Lachance +
-
William Andrea
-
Wolfgang F. Riedl +
-
Xingrong Chen
-
Yago González
-
Yikun Jiang +
-
Yuanhao Geng
-
Yuval +
-
Zero
-
Zhengfei Wang +
-
abmyii
-
alexondor +
-
alm
-
andjhall +
-
anilbey +
-
arnaudlegout +
-
asv-bot +
-
ateki +
-
auderson +
-
bherwerth +
-
bicarlsen +
-
carbonleakage +
-
charles +
-
charlogazzo +
-
code-review-doctor +
-
dataxerik +
-
deponovo
-
dimitra-karadima +
-
dospix +
-
ehallam +
-
ehsan shirvanian +
-
ember91 +
-
eshirvana
-
fractionalhare +
-
gaotian98 +
-
gesoos
-
github-actions[bot]
-
gunghub +
-
hasan-yaman
-
iansheng +
-
iasoon +
-
jbrockmendel
-
joshuabello2550 +
-
jyuv +
-
kouya takahashi +
-
mariana-LJ +
-
matt +
-
mattB1989 +
-
nealxm +
-
partev
-
poloso +
-
realead
-
roib20 +
-
rtpsw
-
ryangilmour +
-
shourya5 +
-
srotondo +
-
stanleycai95 +
-
staticdev +
-
tehunter +
-
theidexisted +
-
tobias.pitters +
-
uncjackg +
-
vernetya
-
wany-oh +
-
wfr +
-
z3c0 +


浙公网安备 33010602011771号