1.5.0 中的新功能(2022年9月19日)#
这是 pandas 1.5.0 中的更改。请参阅 发行说明 以获取包括其他版本 pandas 的完整更新日志。
增强功能#
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 规范。请在 https://data-apis.org/dataframe-protocol/latest/index.html 查看 API 的详细信息。
该协议由两部分组成:
新方法
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)
小的功能改进包括:
在Excel中添加渲染
border和border-{side}CSS 属性的能力 (GH 42276)使关键字参数一致:
Styler.highlight_null()现在接受color并弃用null_color,尽管这仍然向后兼容 (GH 45907)
使用 group_keys 控制索引在 DataFrame.resample() 中#
参数 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 库。更多详情,请参见 IO 文档中的 ORC。
警告
强烈建议使用 conda 安装 pyarrow,因为 pyarrow 存在一些问题。
to_orc()需要 pyarrow>=7.0.0。有关支持的数据类型,请参阅 Arrow 中支持的 ORC 功能。
当前,在将数据框转换为ORC文件时,datetime列中的时区不会被保留。
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)。
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 的模式之一:https://docs.python.org/3/library/tarfile.html#tarfile.open)
read_xml 现在支持 dtype、converters 和 parse_dates#
与其他 IO 方法类似,pandas.read_xml() 现在支持为列分配特定的 dtypes,应用转换器方法,并解析日期 (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[s]
dtype: object
read_xml 现在支持使用 iterparse 处理大型 XML#
对于大小从几百兆字节到千兆字节的非常大的XML文件,pandas.read_xml() 现在支持使用 lxml’s iterparse 和 etree’s 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现在除了字符串和pandas.NA之外,还接受包含类似 nan 的数组(None,np.nan)作为其构造函数中values参数的值。(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()现在支持使用engine关键字进行 Numba 执行 (GH 45428)read_csv()现在支持defaultdict作为dtype参数 (GH 41574)DataFrame.rolling()和Series.rolling()现在支持一个step参数,用于固定长度的窗口 (GH 15354)实现了一个
bool-dtype索引,将一个布尔类型的数组传递给pd.Index现在会保留bool类型,而不是转换为object(GH 45061)实现了一个复杂数据类型的
索引,将一个复杂数据类型的类数组对象传递给pd.Index现在将保留复杂数据类型而不是转换为对象(GH 45845)为
DateOffset添加milliseconds字段支持 (GH 43371)DataFrame.where()尝试在填充值可以无精度损失地转换时保持DataFrame的 dtype (GH 45582)DataFrame.reset_index()现在接受一个names参数,该参数重命名索引名称 (GH 6878)在
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]dtype 并调用未分派到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)Series缩减器(例如min、max、sum、mean)现在可以在 dtype 为数值且提供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)在
Series.set_axis()和DataFrame.set_axis()中添加了copy关键字,允许用户在不必然复制底层数据的情况下在新对象上设置轴 (GH 47932)方法
ExtensionArray.factorize()接受use_na_sentinel=False以确定如何处理空值 (GH 46601)现在,
Dockerfile为 pandas 开发安装了一个专用的pandas-dev虚拟环境,而不是使用base环境 (GH 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 序列化 tz-naive 时间戳与 to_json()#
DataFrame.to_json(), Series.to_json(), 和 Index.to_json() 会错误地将带有 tz-naive 时间戳的 DatetimeArrays/DatetimeIndexes 本地化为 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])
DataFrameGroupBy.value_counts 使用非分组的分类列和 observed=True#
调用 DataFrameGroupBy.value_counts() 时,如果 observed=True,会错误地删除非分组列的非观察类别 (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 变化#
增加依赖项的最小版本#
一些依赖项的最低支持版本已更新。如果已安装,我们现在要求:
包 |
最低版本 |
必需的 |
Changed |
|---|---|---|---|
numpy |
1.20.3 |
X |
X |
mypy (dev) |
0.971 |
X |
|
beautifulsoup4 |
4.9.3 |
X |
|
blosc |
1.21.0 |
X |
|
瓶颈 |
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 开发过程中目前测试的最低版本。低于最低测试版本的可选库可能仍然有效,但不被视为支持。
包 |
最低版本 |
Changed |
|---|---|---|
beautifulsoup4 |
4.9.3 |
X |
blosc |
1.21.0 |
X |
瓶颈 |
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” (复制粘贴) 流程。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)
弃用#
警告
在下一个主要版本发布,2.0中,正在考虑几个较大的API更改,而没有正式的弃用,例如使标准库 zoneinfo 成为默认的时区实现,而不是 pytz,让 Index 支持所有数据类型,而不是有多个子类(CategoricalIndex、Int64Index 等),等等。正在考虑的更改记录在 这个GitHub问题 中,欢迎任何反馈或关注。
基于标签的整数切片在一个带有 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)
以下属性现在是公开的,并且被认为是安全的。
book
check_extension
close
date_format
datetime_format
engine
if_sheet_exists
sheets
supported_extensions
以下属性已被弃用。现在访问它们时会引发 FutureWarning ,并将在未来版本中移除。用户应注意,它们的用法被认为是不安全的,并可能导致意外结果。
cur_sheet
handles
path
save
write_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() 设置值会尝试就地设置值,只有在必要时才会回退到插入新数组。有些情况下不遵循这一规则,例如当使用具有不同数据类型的数组设置整个列时:
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.to_csv()和Series.to_csv()中弃用了关键字line_terminator,请改用lineterminator;这是为了与read_csv()和标准库 ‘csv’ 模块保持一致 (GH 9568)当传递一个非稀疏的
dtype时,SparseArray.astype()、Series.astype()和DataFrame.astype()与SparseDtype的弃用行为。在未来的版本中,这将转换为该非稀疏类型,而不是将其包装在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)当转换为
int64以外的整数类型时,DatetimeIndex.astype()、TimedeltaIndex.astype()、PeriodIndex.astype()的已弃用行为。在未来的版本中,这些将转换为指定的确切类型(而不是总是int64),并且在转换溢出时会引发异常 (GH 45034)弃用了 DataFrame 和 Series 的
__array_wrap__方法,改为依赖标准的 numpy ufuncs (GH 45451)当传递带有时区信息的浮点型数据时,不再将它们视为墙时间(wall-times)到
Series或DatetimeIndex(GH 45573)弃用了
Series.fillna()和DataFrame.fillna()在timedelta64[ns]数据类型和不兼容的填充值时的行为;在未来的版本中,这将转换为通用数据类型(通常是对象)而不是引发错误,匹配其他数据类型的行为 (GH 45746)在
infer_freq()中弃用了warn参数 (GH 45947)在
ExtensionArray.argsort()中弃用允许非关键字参数 (GH 46134)在
DataFrame.any()和DataFrame.all()中,弃用将所有布尔类型的object-dtype 列视为布尔类型,改为显式转换为布尔类型 (GH 46188)方法
DataFrame.quantile()的弃用行为,属性numeric_only将默认为 False。结果中包含 datetime/timedelta 列 (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)已弃用
DataFrameGroupBy.transform()在UDF返回DataFrame时未对齐结果 (GH 45648)当分隔日期无法根据指定的
dayfirst参数解析时,来自to_datetime()的明确警告 (GH 46210)当分隔日期无法根据指定的
dayfirst参数解析时,从to_datetime()发出警告,即使对于省略前导零的日期(例如31/1/2001)也是如此 (GH 47880)已弃用的
Series和Resampler缩减器(例如min,max,sum,mean)在 dtype 为非数值且提供numeric_only=True时引发NotImplementedError;这将在未来版本中引发TypeError(GH 47500)当数据类型为非数字且提供
numeric_only=True时,已弃用的Series.rank()返回空结果;这将在未来版本中引发TypeError(GH 47500)已弃用的参数
errors用于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时,弃用生成单个元素;将返回一个长度为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()中,当其他对象是一个Series时,针对列方向(axis=0)的 Pearson 和 Spearman 相关性的性能改进 (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)在
DataFrameGroupBy.var()和SeriesGroupBy.var()中使用ddof而不是 1 时的性能改进 (GH 48152)当索引是
MultiIndex时,DataFrame.to_records()的性能改进 (GH 47263)当 MultiIndex 包含 DatetimeIndex、TimedeltaIndex 或 ExtensionDtypes 类型的级别时,
MultiIndex.values的性能改进 (GH 46288)当左和/或右为空时,
DataFrame.join()的性能改进 (GH 46015)当目标是一个
MultiIndex时,DataFrame.reindex()和Series.reindex()的性能改进 (GH 46235)在 pyarrow 支持的字符串数组中设置值时的性能改进 (GH 46400)
在
factorize()中的性能提升 (GH 46109)当提供
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"时,datetime 数组的字符串格式化性能得到了提升。(GH 44764)在处理时间数组时,
Series.to_sql()和DataFrame.to_sql()(SQLiteTable) 的性能提升。(GH 44764)对
read_sas()的性能改进 (GH 47404)在
arrays.SparseArray中argmax和argmin的性能改进 (GH 34197)
错误修复#
Categorical#
Categorical.view()中的错误不接受整数数据类型 (GH 25464)当索引的类别是整数类型且索引包含
NaN值时,CategoricalIndex.union()中的错误会错误地引发而不是转换为float64(GH 45362)当连接两个(或更多)无序的
CategoricalIndex变量,其类别是排列时,concat()中的错误会产生不正确的索引值 (GH 24845)
Datetimelike#
在
DataFrame.quantile()中,当使用类似日期时间的 dtypes 且没有行时,错误地返回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)在
DatetimeIndex.tz_localize()中本地化到 UTC 时未能复制底层数据的问题 (GH 46460)DatetimeIndex.resolution()中的错误错误地返回“天”而不是“纳秒”,用于纳秒分辨率索引 (GH 46903)Timestamp中存在一个错误,当使用整数或浮点数值和unit="Y"或unit="M"时,结果略有错误 (GH 47266)当传递另一个
DatetimeArray并且freq=None时,DatetimeArray构造中的错误,错误地从给定数组推断 freq (GH 47296)在
to_datetime()中的一个错误,即使errors=coerce,如果超过50行,会抛出OutOfBoundsDatetime(GH 45319)在将
DateOffset添加到Series时出现错误,不会添加nanoseconds字段 (GH 47856)
Timedelta#
时区#
Numeric#
在
floordiv中,当除以IntegerDtype0时会返回0而不是inf(GH 48223)在
dtype="boolean"的类数组对象上进行pow和mod操作时出现的错误,不像它们的np.bool_对应物 (GH 46063)在将具有
IntegerDtype或FloatingDtype的Series与具有timedelta64[ns]dtype 的类数组对象相乘时,错误地引发了一个 Bug (GH 45622)在
mean()中的一个错误,其中可选依赖bottleneck导致数组长度线性增加的精度损失。bottleneck已禁用以改进mean()的损失为对数线性,但可能会导致性能下降。(GH 42878)
转换#
DataFrame.astype()中的错误未保留子类 (GH 40810)在从包含浮点数的列表或浮点数据类型的类ndarray(例如
dask.Array)构建Series时存在错误,并且给定整数数据类型会引发错误,而不是像使用np.ndarray那样进行类型转换(GH 40110)在
Float64Index.astype()中将无符号整数类型错误地转换为np.int64类型的错误 (GH 45309)在从浮点数据类型转换为无符号整数数据类型时,
Series.astype()和DataFrame.astype()中的错误在存在负值时未能引发 (GH 45151)在
array()中使用FloatingDtype和包含可转换为浮点数的字符串值时,错误地引发 (GH 45424)比较字符串和 datetime64ns 对象时出现错误,导致
OverflowError异常。(GH 45506)泛型抽象数据类型的元类中的错误导致
DataFrame.apply()和Series.apply()在调用内置函数type时引发异常 (GH 46684)DataFrame.to_records()中的错误,如果索引是MultiIndex,则返回不一致的 numpy 类型 (GH 47263)在
orient="list"或orient="index"情况下,DataFrame.to_dict()中的 Bug 没有返回原生类型 (GH 46751)在应用于空
DataFrame且axis=1时,DataFrame.apply()中的错误返回DataFrame而不是Series(GH 39111)当从*不是*由所有NumPy无符号整数标量组成的NumPy
ndarray推断dtype时,没有导致无符号整数dtype (GH 47294)当列名为 pandas 对象(例如
'Timestamp')时,DataFrame.eval()中的 Bug (GH 44603)
字符串#
在使用其他系列作为参数 _pat_ 时,
str.startswith()和str.endswith()中的错误。现在引发TypeError(GH 3485)当字符串包含前导符号时,
Series.str.zfill()中的错误,在符号字符之前填充 ‘0’ 而不是之后,如同标准库中的str.zfill(GH 20868)
Interval#
在将
np.nan设置到整数支持的数组中时,IntervalArray.__setitem__()中的错误引发ValueError而不是TypeError(GH 45484)在使用 datetime64[ns, tz] 作为 dtype 字符串时
IntervalDtype中的 Bug (GH 46999)
索引#
在
DataFrame.iloc()中的一个错误,当在一个包含单个 ExtensionDtype 列的DataFrame上索引单行时,返回的是一个副本而不是底层数据的视图 (GH 45241)在
DataFrame.__getitem__()中存在一个错误,即使选择了唯一列,当DataFrame有重复列时返回副本 (GH 45316, GH 41062)Series.align()中的错误不会在两个 MultiIndexes 交集相同时创建具有级别并集的MultiIndex(GH 45224)在将 NA 值(
None或np.nan)设置到具有基于 int 的IntervalDtype的Series中时,错误地转换为 object dtype,而不是基于 float 的IntervalDtype(GH 45568)在
ExtensionDtype列中使用df.iloc[:, i] = values设置索引值的错误,其中values与df.iloc[:, i]具有相同的 dtype,错误地插入了一个新数组而不是就地设置 (GH 33457)在使用整数键设置无法就地设置的值时,当使用非整数
Index的Series.__setitem__()中存在错误,应引发ValueError而不是转换为通用 dtype (GH 45070)DataFrame.loc()中的错误,在将值作为列表设置到DataFrame中时,不会将None转换为NA(GH 47987)在
Series.__setitem__()中设置不兼容的值到PeriodDtype或IntervalDtypeSeries时,当使用布尔掩码索引时会引发错误,但在使用其他等效索引器时会强制转换;现在这些情况一致地强制转换,包括Series.mask()和Series.where()(GH 45768)在具有类似日期时间的多列的
DataFrame.where()中存在一个错误,无法将结果向下转换为与其他数据类型一致 (GH 45837)在
isin()中,当使用无符号整数类型和没有类型的类列表参数时,会向上转换为float64的错误 (GH 46485)在未使用
MultiIndex的情况下,使用多个键时,Series.loc.__setitem__()和Series.loc.__getitem__()中的错误未引发 (GH 13831)在指定了
level但没有给出MultiIndex时,Index.reindex()中的 Bug 引发了AssertionError;现在忽略level(GH 35132)当为一个
Series数据类型设置一个过大的值时,未能强制转换为通用类型的问题 (GH 26049, GH 32878)在
loc.__setitem__()中的错误,将range键作为位置处理而不是基于标签处理 (GH 45479)在
DataFrame.__setitem__()中存在一个错误,当使用标量键和DataFrame作为值时,会将扩展数组的数据类型转换为对象 (GH 46896)在设置标量到可空 pandas 数据类型时,
Series.__setitem__()中的错误不会在标量无法(无损地)转换为可空类型时引发TypeError(GH 45404)在设置包含
NA的boolean数据类型值时,Series.__setitem__()中的错误不正确地引发,而不是转换为boolean数据类型 (GH 45462)在
Index不匹配时,包含NA的布尔索引器引发Series.loc()的错误 (GH 46551)在
Series.__setitem__()中的一个错误,当设置NA到一个数值类型的Series时,会错误地向上转换为对象类型,而不是将值视为np.nan(GH 44199)当设置值到一列且右侧是一个字典时,
DataFrame.loc()中的错误 (GH 47216)在
Series.__setitem__()中存在一个错误,当使用datetime64[ns]数据类型、全为False的布尔掩码和不兼容的值时,错误地转换为object类型,而不是保留datetime64[ns]数据类型 (GH 45967)在索引器来自带有
NA的布尔类型时,Index.__getitem__()中的错误引发ValueError(GH 45806)在
Series.mask()中使用inplace=True或在用布尔掩码设置小整数类型值时错误地引发 (GH 45750)在
inplace=True和ExtensionDtype列的情况下,DataFrame.mask()中的错误不正确地引发 (GH 45577)在使用具有类似日期时间值的对象类型行索引从 DataFrame 获取列时存在错误:生成的 Series 现在保留了父 DataFrame 中的确切对象类型索引 (GH 42950)
在
DataFrame.__getattribute__()中存在一个错误,如果列具有"string"dtype,则会引发AttributeError(GH 46185)在比较扩展数组类型和numpy类型时,
DataFrame.compare()返回所有NaN列的错误 (GH 44014)在
DataFrame.where()中使用"boolean"掩码为 numpy 数据类型设置错误值的错误 (GH 44014)在
DatetimeIndex上使用np.str_键进行索引时错误地引发 (GH 45580)当索引包含
NaN值时,CategoricalIndex.get_indexer()中的错误,导致在目标中但不在索引中的元素被映射到 NaN 元素的索引,而不是 -1 (GH 45361)在将大整数值设置到具有
float32或float16dtype 的Series中时,错误地更改了这些值,而不是强制转换为float64dtype (GH 45844)Series.asof()和DataFrame.asof()中的错误不正确地将布尔类型结果转换为float64类型 (GH 16063)在
NDFrame.xs()、DataFrame.iterrows()、DataFrame.loc()和DataFrame.iloc()中的错误不会总是传播元数据 (GH 28283)在
DataFrame.sum()中的错误:如果输入包含 NaNs,min_count 会更改 dtype (GH 46947)在
IntervalTree中导致无限递归的错误。(GH 46658)PeriodIndex在索引NA时引发AttributeError,而不是在其位置放置NaT的错误。(GH 46673)在
DataFrame.at()中的错误允许修改多个列 (GH 48296)
缺失#
在
Series.fillna()和DataFrame.fillna()中存在一个错误,在某些情况下,当不存在NA值时,downcast关键字未被尊重 (GH 45423)在
Series.fillna()和DataFrame.fillna()中使用IntervalDtype和不兼容的值时,应进行类型转换而不是引发错误 (GH 45796)在
Series.map()中的错误,如果不尊重na_action参数,如果映射器是一个dict或Series(GH 47527)在
DataFrame.interpolate()中存在一个错误,当使用inplace=False时,对象类型的列没有返回一个副本 (GH 45791)DataFrame.dropna()中的错误允许设置how和thresh不兼容的参数 (GH 46575)在
DataFrame.fillna()中的错误忽略了axis当DataFrame是单个块时 (GH 47713)
MultiIndex#
在以负步长和非空起始/停止值对
MultiIndex进行切片时,DataFrame.loc()返回空结果的错误 (GH 46156)在以非-1的负步长对
MultiIndex进行切片时,DataFrame.loc()中的错误引发 (GH 46156)在以负步长对
MultiIndex进行切片时,DataFrame.loc()引发错误,并且对非整数标记的索引级别进行切片 (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)read_excel()中的错误在某些skiprows可调用对象中会导致无限循环 (GH 45585)在
DataFrame.info()中的一个错误,当在空的DataFrame上调用时,输出的末尾会省略一个新行 (GH 45494)read_csv()中的错误,在engine="c"时无法识别on_bad_lines="warn"的换行符 (GH 41710)DataFrame.to_csv()中的错误不尊重Float64数据类型的float_format(GH 45991)在所有情况下,
read_csv()中的错误不尊重为索引列指定的转换器 (GH 40589)在
index_col=False时,read_csv()将第二行解释为Index名称的错误 (GH 46569)Bug in
read_parquet()whenengine="pyarrow"which caused partial write to disk when column of unsupported datatype was passed (GH 44914)DataFrame.to_excel()和ExcelWriter中的错误在将空 DataFrame 写入.ods文件时会引发 (GH 45793)Bug in
read_csv()ignoring non-existing header row forengine="python"(GH 47400)在
header引用不存在的行时,read_excel()中的错误引发不受控制的IndexError(GH 43143)在
read_html()中的一个错误,其中围绕<br>的元素在没有空格的情况下被连接在一起 (GH 29528)当数据长度大于表头时,
read_csv()中的错误导致usecols中的可调用对象期望字符串 (GH 46997)在带有
datetime64[ns]子类型的 Interval dtype 的 Parquet 往返中的 Bug (GH 45881)在读取包含xml元素之间换行符的
.ods文件时,read_excel()存在一个错误 (GH 45598)Bug in
read_parquet()whenengine="fastparquet"where the file was not closed on error (GH 46555)DataFrame.to_html()现在在border关键字设置为False时,从<table>元素中排除border属性。在处理某些类型的压缩 SAS7BDAT 文件时,
read_sas()存在一个错误 (GH 35545)在未给出名称时,
read_excel()中的错误未向前填充MultiIndex(GH 47487)read_sas()中的错误返回了None而不是空 DataFrame 用于零行的 SAS7BDAT 文件 (GH 18198)在
MultiIndex中使用扩展数组时,DataFrame.to_string()中的错误使用了错误的缺失值 (GH 47986)在
StataWriter中的一个错误,其中值标签总是以默认编码写入 (GH 46750)在
StataWriterUTF8中的一个错误,其中一些有效字符从变量名中被删除(GH 47276)当使用
MultiIndex写入一个空的数据框时,DataFrame.to_excel()中的错误 (GH 19543)在包含0x40控制字节的RLE压缩SAS7BDAT文件中,
read_sas()存在错误 (GH 31243)在
read_sas()中导致列名混乱的错误 (GH 31243)在包含0x00控制字节的RLE压缩SAS7BDAT文件中,
read_sas()存在错误 (GH 47099)在
use_nullable_dtypes=True的情况下,read_parquet()中的一个错误,返回了float64类型而不是可空Float64类型 (GH 45694)在
DataFrame.to_json()中的错误,当使用PeriodDtype时,不会在通过read_json()读回时进行序列化往返 (GH 44720)在读取带有中文字符标签的XML文件时,
read_xml()存在一个错误,并且会引发XMLSyntaxError(GH 47902)
周期#
Period从PeriodArray中减去时返回错误结果的错误 (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时,错误地引发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)修复在未设置 ylabel 时,
Series.plot()中显示 “None” 作为 ylabel 的问题 (GH 46129)在
DataFrame.plot()中的一个错误,导致在绘制季度系列时,xticks 和垂直网格位置不当 (GH 47602)在
DataFrame.plot()中的一个错误,阻止了为次要 y 轴设置 y 轴标签、限制和刻度 (GH 47753)
分组/重采样/滚动#
DataFrame.resample()中的错误忽略了TimedeltaIndex上的closed="right"(GH 45414)当
func="size"并且输入的 DataFrame 有多个列时,DataFrameGroupBy.transform()中的错误失败 (GH 27469)在
DataFrameGroupBy.size()和DataFrameGroupBy.transform()中使用func="size"时,当axis=1会产生不正确的结果 (GH 45715)当
DataFrame的列数多于行数时,使用axis=1和engine='numba'的ExponentialMovingWindow.mean()存在错误 (GH 46086)使用
engine="numba"时出现错误,当修改engine_kwargs时会返回相同的 jitted 函数 (GH 46086)DataFrameGroupBy.transform()中的错误在axis=1且func为"first"或"last"时失败 (GH 45986)在
skipna=False的情况下,DataFrameGroupBy.cumsum()中的错误导致不正确的结果 (GH 46216)在
DataFrameGroupBy.sum(),SeriesGroupBy.sum(),DataFrameGroupBy.prod(),SeriesGroupBy.prod, :meth:().DataFrameGroupBy.cumsum`, 和SeriesGroupBy.cumsum()中,整数类型失去精度的错误 (GH 37493)DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()中的错误,在timedelta64[ns]数据类型下未能识别NaT为空值 (GH 46216)DataFrameGroupBy.cumsum()和SeriesGroupBy.cumsum()中的整数类型存在错误,当总和大于数据类型的最大值时会导致溢出 (GH 37493)在可空 dtypes 的情况下,
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)在空组和
uint64数据类型下,DataFrameGroupBy.max()和SeriesGroupBy.max()中的错误不正确地引发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)在使用
on时,DataFrame.resample()的归约方法中的错误会尝试聚合提供的列 (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)
重塑#
在具有整数数据类型的
Series和具有整数类别和包含NaN值的CategoricalDtype之间的concat()中存在一个错误,该错误会转换为对象数据类型,而不是float64(GH 45359)在
get_dummies()中存在一个错误,该错误选择了对象和分类数据类型,但没有选择字符串 (GH 44965)当将一个
MultiIndex对齐到一个带有另一个MultiIndex的Series时,DataFrame.align()中的错误 (GH 46001)在
IntegerDtype或FloatingDtype数组进行连接时出现的错误,结果的 dtype 没有反映非可空 dtypes 的行为 (GH 46379)当
join="outer"和sort=True时,concat()中的错误导致列的 dtype 丢失 (GH 47329)在具有相同键的情况下,对
MultiIndex进行索引时,concat()中的错误会导致错误 (GH 46519)当
dropna=True且聚合列具有扩展数组数据类型时,pivot_table()中的错误引发TypeError(GH 47477)Bug in
merge()raising error forhow="cross"when usingFIPSmode in ssl library (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包含字符串数据类型列时,wide_to_long()中的错误会引发 (GH 46044)使用分类索引时
DataFrame.join()中的错误导致意外重排序 (GH 47812)
Sparse#
在
Series.where()和DataFrame.where()中使用SparseDtype时无法保留数组的fill_value的错误 (GH 45691)SparseArray.unique()中的错误未能保持原始元素的顺序 (GH 47809)
ExtensionArray#
IntegerArray.searchsorted()和FloatingArray.searchsorted()中的错误,在处理np.nan时返回不一致的结果 (GH 45255)
Styler#
尝试对空DataFrame子集应用样式功能时出现错误 (GH 45313)
CSSToExcelConverter中的错误导致在使用xlsxwriter引擎时,提供边框颜色但没有边框样式会导致TypeError(GH 42276)在
Styler.set_sticky()中的错误导致在暗模式下出现白色文字在白色背景上 (GH 46984)在
Styler.to_latex()中的错误导致当clines="all;data"且DataFrame没有行时出现UnboundLocalError。 (GH 47203)在使用
xlsxwriter引擎时,当使用vertical-align: middle;时,Styler.to_excel()中的 Bug (GH 30107)当对带有布尔列标签的 DataFrame 应用样式时出现错误 (GH 47838)
元数据#
修复了
DataFrame.melt()中的固定元数据传播 (GH 28283)修复了
DataFrame.explode()中的固定元数据传播 (GH 28283)
其他#
在
names=True和check_order=False的情况下,assert_index_equal()中的 Bug 未检查名称 (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 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
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 +