版本 0.17.0 (2015 年 10 月 9 日)#

这是继 0.16.2 之后的一个主要版本,包含少量 API 变更、一些新特性、增强功能和性能改进,以及大量错误修复。我们建议所有用户升级到此版本。

警告

pandas >= 0.17.0 将不再支持与 Python 3.2 版本的兼容性 (GH 9118)

警告

pandas.io.data 包已弃用,将被 pandas-datareader 包取代。这将允许数据模块独立于 pandas 安装进行更新。pandas-datareader v0.1.1 的 API 与 pandas v0.17.0 中的完全相同 (GH 8961, GH 10861)。

安装 pandas-datareader 后,您可以轻松更改导入方式

from pandas.io import data, wb

变为

from pandas_datareader import data, wb

主要亮点包括

  • 在部分 cython 操作中释放全局解释器锁 (GIL),详情请参见此处

  • 绘图方法现在可以作为 .plot 访问器的属性使用,详情请参见此处

  • 排序 API 已进行改进,以消除一些长期存在的不一致性,详情请参见此处

  • 支持将带时区的 datetime64[ns] 作为一级 dtype,详情请参见此处

  • 当遇到不可解析的格式时,to_datetime 的默认行为将是 raise 异常,而之前会返回原始输入。此外,日期解析函数现在返回一致的结果。详情请参见此处

  • HDFStoredropna 的默认值已更改为 False,默认存储所有行,即使它们全部为 NaN,详情请参见此处

  • Datetime 访问器 (dt) 现在支持 Series.dt.strftime 用于生成类似 datetime 的格式化字符串,以及 Series.dt.total_seconds 用于生成 timedelta 的总秒数。详情请参见此处

  • PeriodPeriodIndex 现在可以处理乘法频率 (multiplied freq),如 3D,表示 3 天跨度。详情请参见此处

  • 开发安装的 pandas 版本现在将具有符合 PEP440 标准的版本字符串 (GH 9518)

  • 添加了对使用 Air Speed Velocity 库进行基准测试的开发支持 (GH 8361)

  • 支持读取 SAS xport 文件,详情请参见此处

  • 比较 SAS 与 pandas 的文档,详情请参见此处

  • 移除了自动 TimeSeries 广播功能(自 0.8.0 版本起已弃用),详情请参见此处

  • 纯文本显示格式可以选择与 Unicode 东亚字符宽度对齐,详情请参见此处

  • 与 Python 3.5 的兼容性 (GH 11097)

  • 与 matplotlib 1.5.0 的兼容性 (GH 11111)

更新前请检查 API 变更弃用功能

新特性#

带时区的 Datetime#

我们正在添加一个原生支持带时区 datetime 的实现。以前,SeriesDataFrame可以被赋予带时区的 datetime,并会作为 object dtype 工作。当行数很多时,这会导致性能问题。更多详情请参见文档。 (GH 8260, GH 10763, GH 11034)。

新的实现允许在所有行中拥有单一时区,并以高性能方式执行操作。

In [1]: df = pd.DataFrame(
   ...:     {
   ...:         "A": pd.date_range("20130101", periods=3),
   ...:         "B": pd.date_range("20130101", periods=3, tz="US/Eastern"),
   ...:         "C": pd.date_range("20130101", periods=3, tz="CET"),
   ...:     }
   ...: )
   ...: 

In [2]: df
Out[2]: 
           A                         B                         C
0 2013-01-01 2013-01-01 00:00:00-05:00 2013-01-01 00:00:00+01:00
1 2013-01-02 2013-01-02 00:00:00-05:00 2013-01-02 00:00:00+01:00
2 2013-01-03 2013-01-03 00:00:00-05:00 2013-01-03 00:00:00+01:00

[3 rows x 3 columns]

In [3]: df.dtypes
Out[3]: 
A                datetime64[ns]
B    datetime64[ns, US/Eastern]
C           datetime64[ns, CET]
Length: 3, dtype: object
In [4]: df.B
Out[4]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
Name: B, Length: 3, dtype: datetime64[ns, US/Eastern]

In [5]: df.B.dt.tz_localize(None)
Out[5]: 
0   2013-01-01
1   2013-01-02
2   2013-01-03
Name: B, Length: 3, dtype: datetime64[ns]

这也使用了一种新的 dtype 表示形式,其外观和感觉与它的 numpy 近亲 datetime64[ns] 非常相似。

In [6]: df["B"].dtype
Out[6]: datetime64[ns, US/Eastern]

In [7]: type(df["B"].dtype)
Out[7]: pandas.core.dtypes.dtypes.DatetimeTZDtype

注意

由于 dtype 更改,底层 DatetimeIndex 的字符串表示形式略有不同,但在功能上它们是相同的。

之前行为

In [1]: pd.date_range('20130101', periods=3, tz='US/Eastern')
Out[1]: DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
                       '2013-01-03 00:00:00-05:00'],
                      dtype='datetime64[ns]', freq='D', tz='US/Eastern')

In [2]: pd.date_range('20130101', periods=3, tz='US/Eastern').dtype
Out[2]: dtype('<M8[ns]')

新行为

In [8]: pd.date_range("20130101", periods=3, tz="US/Eastern")
Out[8]: 
DatetimeIndex(['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00',
               '2013-01-03 00:00:00-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq='D')

In [9]: pd.date_range("20130101", periods=3, tz="US/Eastern").dtype
Out[9]: datetime64[ns, US/Eastern]

释放 GIL#

我们正在部分 cython 操作中释放全局解释器锁 (GIL)。这将允许其他线程在计算期间同时运行,可能通过多线程带来性能提升。特别是 groupbynsmallestvalue_counts 和一些索引操作会从中受益。 (GH 8882)

例如,以下代码中的 groupby 表达式将在分解步骤(例如 df.groupby('key'))期间释放 GIL,.sum() 操作也一样。

N = 1000000
ngroups = 10
df = DataFrame(
    {"key": np.random.randint(0, ngroups, size=N), "data": np.random.randn(N)}
)
df.groupby("key")["data"].sum()

释放 GIL 有利于使用线程处理用户交互(例如 QT)或执行多线程计算的应用程序。一个可以处理这些并行计算的很好的例子是 dask 库。

绘图子方法#

Series 和 DataFrame 的 .plot() 方法允许通过提供 kind 关键字参数来自定义绘图类型。遗憾的是,许多这类绘图使用了不同的必需和可选关键字参数,这使得从数十个可能的参数中找出给定绘图类型使用了哪些参数变得困难。

为了缓解此问题,我们添加了一个新的可选绘图接口,它将每种绘图类型作为 .plot 属性的一个方法暴露出来。现在,除了编写 series.plot(kind=<kind>, ...),您还可以使用 series.plot.<kind>(...)

In [10]: df = pd.DataFrame(np.random.rand(10, 2), columns=['a', 'b'])

In [11]: df.plot.bar()
../_images/whatsnew_plot_submethods.png

作为这项更改的结果,这些方法现在都可以通过 tab 补全来发现

In [12]: df.plot.<TAB>  # noqa: E225, E999
df.plot.area     df.plot.barh     df.plot.density  df.plot.hist     df.plot.line     df.plot.scatter
df.plot.bar      df.plot.box      df.plot.hexbin   df.plot.kde      df.plot.pie

每个方法的签名仅包含相关参数。目前,这些参数仅限于必需参数,但将来也会包含可选参数。有关概述,请参阅新的绘图 API 文档。

dt 访问器的附加方法#

Series.dt.strftime#

我们现在支持 Series.dt.strftime 方法,用于对类似 datetime 的对象生成格式化字符串 (GH 10110)。示例:

# DatetimeIndex
In [13]: s = pd.Series(pd.date_range("20130101", periods=4))

In [14]: s
Out[14]: 
0   2013-01-01
1   2013-01-02
2   2013-01-03
3   2013-01-04
Length: 4, dtype: datetime64[ns]

In [15]: s.dt.strftime("%Y/%m/%d")
Out[15]: 
0    2013/01/01
1    2013/01/02
2    2013/01/03
3    2013/01/04
Length: 4, dtype: object
# PeriodIndex
In [16]: s = pd.Series(pd.period_range("20130101", periods=4))

In [17]: s
Out[17]: 
0    2013-01-01
1    2013-01-02
2    2013-01-03
3    2013-01-04
Length: 4, dtype: period[D]

In [18]: s.dt.strftime("%Y/%m/%d")
Out[18]: 
0    2013/01/01
1    2013/01/02
2    2013/01/03
3    2013/01/04
Length: 4, dtype: object

字符串格式与 Python 标准库相同,详情可参见此处

Series.dt.total_seconds#

类型为 timedelta64pd.Series 新增了方法 .dt.total_seconds(),用于返回 timedelta 的总秒数 (GH 10817)。

# TimedeltaIndex
In [19]: s = pd.Series(pd.timedelta_range("1 minutes", periods=4))

In [20]: s
Out[20]: 
0   0 days 00:01:00
1   1 days 00:01:00
2   2 days 00:01:00
3   3 days 00:01:00
Length: 4, dtype: timedelta64[ns]

In [21]: s.dt.total_seconds()
Out[21]: 
0        60.0
1     86460.0
2    172860.0
3    259260.0
Length: 4, dtype: float64

Period 频率增强#

PeriodPeriodIndexperiod_range 现在可以接受乘法频率 (multiplied freq)。此外,Period.freqPeriodIndex.freq 现在像 DatetimeIndex 一样存储为 DateOffset 实例,而不是 str (GH 7811)。

乘法频率表示相应长度的跨度。下面的示例创建了一个 3 天的周期。加法和减法将按照其跨度移动周期。

In [22]: p = pd.Period("2015-08-01", freq="3D")

In [23]: p
Out[23]: Period('2015-08-01', '3D')

In [24]: p + 1
Out[24]: Period('2015-08-04', '3D')

In [25]: p - 2
Out[25]: Period('2015-07-26', '3D')

In [26]: p.to_timestamp()
Out[26]: Timestamp('2015-08-01 00:00:00')

In [27]: p.to_timestamp(how="E")
Out[27]: Timestamp('2015-08-03 23:59:59.999999999')

您可以在 PeriodIndexperiod_range 中使用乘法频率。

In [28]: idx = pd.period_range("2015-08-01", periods=4, freq="2D")

In [29]: idx
Out[29]: PeriodIndex(['2015-08-01', '2015-08-03', '2015-08-05', '2015-08-07'], dtype='period[2D]')

In [30]: idx + 1
Out[30]: PeriodIndex(['2015-08-03', '2015-08-05', '2015-08-07', '2015-08-09'], dtype='period[2D]')

支持 SAS XPORT 文件#

read_sas() 提供了读取 SAS XPORT 格式文件的支持。 (GH 4052)。

df = pd.read_sas("sas_xport.xpt")

还可以获取一个迭代器并增量读取 XPORT 文件。

for df in pd.read_sas("sas_xport.xpt", chunksize=10000):
    do_something(df)

更多详情请参见文档

.eval() 中支持数学函数#

eval() 现在支持调用数学函数 (GH 4893)

df = pd.DataFrame({"a": np.random.randn(10)})
df.eval("b = sin(a)")

支持的数学函数包括 sin, cos, exp, log, expm1, log1p, sqrt, sinh, cosh, tanh, arcsin, arccos, arctan, arccosh, arcsinh, arctanh, absarctan2

这些函数映射到 NumExpr 引擎的内部函数 (intrinsics)。对于 Python 引擎,它们映射到 NumPy 调用。

Excel 与 MultiIndex 的变更#

在版本 0.16.2 中,具有 MultiIndex 列的 DataFrame 无法通过 to_excel 写入 Excel。此功能已添加 (GH 10564),同时更新了 read_excel,以便可以通过在 headerindex_col 参数中指定哪些列/行构成 MultiIndex 来无损读取数据 (GH 4679)。

更多详情请参见文档

In [31]: df = pd.DataFrame(
   ....:     [[1, 2, 3, 4], [5, 6, 7, 8]],
   ....:     columns=pd.MultiIndex.from_product(
   ....:         [["foo", "bar"], ["a", "b"]], names=["col1", "col2"]
   ....:     ),
   ....:     index=pd.MultiIndex.from_product([["j"], ["l", "k"]], names=["i1", "i2"]),
   ....: )
   ....: 

In [32]: df
Out[32]: 
col1  foo    bar   
col2    a  b   a  b
i1 i2              
j  l    1  2   3  4
   k    5  6   7  8

[2 rows x 4 columns]

In [33]: df.to_excel("test.xlsx")

In [34]: df = pd.read_excel("test.xlsx", header=[0, 1], index_col=[0, 1])

In [35]: df
Out[35]: 
col1  foo    bar   
col2    a  b   a  b
i1 i2              
j  l    1  2   3  4
   k    5  6   7  8

[2 rows x 4 columns]

之前,如果序列化数据包含索引名称,则需要在 read_excel 中指定 has_index_names 参数。对于 0.17.0 版本,to_excel 的输出格式已更改,使此关键字不再必要 - 更改如下所示。

旧版

../_images/old-excel-index.png

新版

../_images/new-excel-index.png

警告

在 0.16.2 或更早版本中保存的、包含索引名称的 Excel 文件仍然可以读入,但必须将 has_index_names 参数指定为 True

Google BigQuery 增强功能#

  • 如果目标表/数据集不存在,增加了使用 pandas.io.gbq.to_gbq() 函数自动创建表/数据集的功能。 (GH 8325, GH 11121)。

  • 调用 pandas.io.gbq.to_gbq() 函数时,增加了通过 if_exists 参数替换现有表和 schema 的功能。更多详情请参见文档 (GH 8325)。

  • gbq 模块中的 InvalidColumnOrderInvalidPageToken 将引发 ValueError,而不是 IOError

  • generate_bq_schema() 函数现已弃用,并将在未来版本中移除 (GH 11121)。

  • gbq 模块现在将支持 Python 3 (GH 11094)。

显示与 Unicode 东亚字符宽度对齐#

警告

启用此选项会影响 DataFrameSeries 的打印性能(大约慢 2 倍)。仅在实际需要时使用。

一些东亚国家使用宽度相当于 2 个字母的 Unicode 字符。如果 DataFrameSeries 包含这些字符,默认输出将无法正确对齐。添加了以下选项以实现对这些字符的精确处理。

  • display.unicode.east_asian_width:是否使用 Unicode 东亚字符宽度计算显示文本宽度。 (GH 2612)

  • display.unicode.ambiguous_as_wide:是否将属于 Ambiguous 的 Unicode 字符作为宽字符处理。 (GH 11102)

In [36]: df = pd.DataFrame({u"国籍": ["UK", u"日本"], u"名前": ["Alice", u"しのぶ"]})

In [37]: df
Out[37]: 
   国籍     名前
0  UK  Alice
1  日本    しのぶ

[2 rows x 2 columns]
In [38]: pd.set_option("display.unicode.east_asian_width", True)

In [39]: df
Out[39]: 
   国籍    名前
0    UK   Alice
1  日本  しのぶ

[2 rows x 2 columns]

更多详情,请参见此处

其他增强功能#

  • 支持 openpyxl >= 2.2。样式支持的 API 现在已稳定 (GH 10125)。

  • merge 现在接受参数 indicator,该参数向输出对象添加一个 Categorical 类型的列(默认名为 _merge),其取值为 (GH 8790):

    观察来源

    _merge 的值

    合并键仅在 'left' 帧中

    left_only

    合并键仅在 'right' 帧中

    right_only

    合并键在两个帧中都存在

    both

    In [40]: df1 = pd.DataFrame({"col1": [0, 1], "col_left": ["a", "b"]})
    
    In [41]: df2 = pd.DataFrame({"col1": [1, 2, 2], "col_right": [2, 2, 2]})
    
    In [42]: pd.merge(df1, df2, on="col1", how="outer", indicator=True)
    Out[42]: 
       col1 col_left  col_right      _merge
    0     0        a        NaN   left_only
    1     1        b        2.0        both
    2     2      NaN        2.0  right_only
    3     2      NaN        2.0  right_only
    
    [4 rows x 4 columns]
    

    更多详情,请参见更新的文档

  • pd.to_numeric 是一个新函数,用于将字符串强制转换为数字(可能带强制转换)(GH 11133)。

  • 如果未对列进行合并,pd.merge 现在将允许重复的列名 (GH 10639)。

  • pd.pivot 现在将允许将索引作为 None 传递 (GH 3962)。

  • 如果提供了 Series 名称,pd.concat 现在将使用现有的 Series 名称 (GH 10698)。

    In [43]: foo = pd.Series([1, 2], name="foo")
    
    In [44]: bar = pd.Series([1, 2])
    
    In [45]: baz = pd.Series([4, 5])
    

    之前行为

    In [1]: pd.concat([foo, bar, baz], axis=1)
    Out[1]:
          0  1  2
       0  1  1  4
       1  2  2  5
    

    新行为

    In [46]: pd.concat([foo, bar, baz], axis=1)
    Out[46]: 
       foo  0  1
    0    1  1  4
    1    2  2  5
    
    [2 rows x 3 columns]
    
  • DataFrame 新增了 nlargestnsmallest 方法 (GH 10393)。

  • 添加了 limit_direction 关键字参数,它与 limit 一起使用,使 interpolate 能够向前、向后或双向填充 NaN 值 (GH 9218, GH 10420, GH 11115)。

    In [47]: ser = pd.Series([np.nan, np.nan, 5, np.nan, np.nan, np.nan, 13])
    
    In [48]: ser.interpolate(limit=1, limit_direction="both")
    Out[48]: 
    0     NaN
    1     5.0
    2     5.0
    3     7.0
    4     NaN
    5    11.0
    6    13.0
    Length: 7, dtype: float64
    
  • 添加了 DataFrame.round 方法,用于将值舍入到可变的小数位数 (GH 10568)。

    In [49]: df = pd.DataFrame(
       ....:     np.random.random([3, 3]),
       ....:     columns=["A", "B", "C"],
       ....:     index=["first", "second", "third"],
       ....: )
       ....: 
    
    In [50]: df
    Out[50]: 
                   A         B         C
    first   0.126970  0.966718  0.260476
    second  0.897237  0.376750  0.336222
    third   0.451376  0.840255  0.123102
    
    [3 rows x 3 columns]
    
    In [51]: df.round(2)
    Out[51]: 
               A     B     C
    first   0.13  0.97  0.26
    second  0.90  0.38  0.34
    third   0.45  0.84  0.12
    
    [3 rows x 3 columns]
    
    In [52]: df.round({"A": 0, "C": 2})
    Out[52]: 
              A         B     C
    first   0.0  0.966718  0.26
    second  1.0  0.376750  0.34
    third   0.0  0.840255  0.12
    
    [3 rows x 3 columns]
    
  • drop_duplicatesduplicated 现在接受一个 keep 关键字来指定保留第一个、最后一个或所有重复项。take_last 关键字已弃用,详见 此处 (GH 6511, GH 8505)

    In [53]: s = pd.Series(["A", "B", "C", "A", "B", "D"])
    
    In [54]: s.drop_duplicates()
    Out[54]: 
    0    A
    1    B
    2    C
    5    D
    Length: 4, dtype: object
    
    In [55]: s.drop_duplicates(keep="last")
    Out[55]: 
    2    C
    3    A
    4    B
    5    D
    Length: 4, dtype: object
    
    In [56]: s.drop_duplicates(keep=False)
    Out[56]: 
    2    C
    5    D
    Length: 2, dtype: object
    
  • Reindex 现在有一个 tolerance 参数,允许更精细地控制 重新索引填充时的限制 (GH 10411)

    In [57]: df = pd.DataFrame({"x": range(5), "t": pd.date_range("2000-01-01", periods=5)})
    
    In [58]: df.reindex([0.1, 1.9, 3.5], method="nearest", tolerance=0.2)
    Out[58]: 
           x          t
    0.1  0.0 2000-01-01
    1.9  2.0 2000-01-03
    3.5  NaN        NaT
    
    [3 rows x 2 columns]
    

    当用于 DatetimeIndexTimedeltaIndexPeriodIndex 时,如果可能,tolerance 将被强制转换为 Timedelta。这允许您使用字符串指定容差

    In [59]: df = df.set_index("t")
    
    In [60]: df.reindex(pd.to_datetime(["1999-12-31"]), method="nearest", tolerance="1 day")
    Out[60]: 
                x
    1999-12-31  0
    
    [1 rows x 1 columns]
    

    tolerance 也通过更低级别的 Index.get_indexerIndex.get_loc 方法公开。

  • 添加了在使用 TimeDeltaIndex 进行重采样时使用 base 参数的功能 (GH 10530)

  • DatetimeIndex 可以使用包含 NaT 的字符串实例化 (GH 7599)

  • to_datetime 现在可以接受 yearfirst 关键字 (GH 7599)

  • 大于 Day 偏移量的 pandas.tseries.offsets 现在可以与 Series 一起用于加法/减法 (GH 10699)。更多详情请参阅文档

  • pd.Timedelta.total_seconds() 现在返回 Timedelta 持续时间的纳秒精度(以前是微秒精度) (GH 10939)

  • PeriodIndex 现在支持与 np.ndarray 进行算术运算 (GH 10638)

  • 支持对 Period 对象进行 pickling (GH 10439)

  • .as_blocks 现在将接受一个可选参数 copy,以返回数据的副本,默认为复制(与之前版本的行为一致),(GH 9607)

  • DataFrame.filterregex 参数现在可以处理数字列名,而不是引发 ValueError (GH 10384)。

  • 支持通过 URL 读取 gzip 压缩文件,可以通过显式设置 compression 参数,或通过响应中是否存在 HTTP Content-Encoding 头来推断 (GH 8685)

  • 支持使用 StringIO/BytesIO 在内存中写入 Excel 文件 (GH 7074)

  • 支持在 ExcelWriter 中将列表和字典序列化为字符串 (GH 8188)

  • SQL io 函数现在接受 SQLAlchemy connectable。(GH 7877)

  • pd.read_sqlto_sql 可以接受数据库 URI 作为 con 参数 (GH 10214)

  • read_sql_table 现在允许从视图中读取 (GH 10750)。

  • 在使用 table 格式时,支持将复杂值写入 HDFStores (GH 10447)

  • 当 HDF 文件包含单个数据集时,支持使用 pd.read_hdf 而无需指定 key (GH 10443)

  • pd.read_stata 现在将读取 Stata 118 类型文件。(GH 9882)

  • msgpack 子模块已更新到 0.4.6 版本,并具有向后兼容性 (GH 10581)

  • DataFrame.to_dict 现在接受 orient='index' 关键字参数 (GH 10844)。

  • 如果传递的函数返回一个字典且 reduce=True,则 DataFrame.apply 将返回一个由字典组成的 Series (GH 8735)。

  • 允许将 kwargs 传递给插值方法 (GH 10378)。

  • 改进了连接空的 Dataframe 对象可迭代对象时的错误消息 (GH 9157)

  • pd.read_csv 现在可以增量读取 bz2 压缩文件,并且 C 解析器可以从 AWS S3 读取 bz2 压缩文件 (GH 11070, GH 11072)。

  • pd.read_csv 中,将 s3n://s3a:// URL 识别为指定 S3 文件存储 (GH 11070, GH 11071)。

  • 从 AWS S3 增量读取 CSV 文件,而不是先下载整个文件。(Python 2 中压缩文件仍需要完整文件下载。)(GH 11070, GH 11073)

  • pd.read_csv 现在能够推断从 AWS S3 存储读取的文件的压缩类型 (GH 11070, GH 11074)。

向后不兼容的 API 更改#

排序 API 的更改#

排序 API 长期存在一些不一致之处。(GH 9816, GH 8239)。

以下是 0.17.0 版本之前的 API 摘要

  • Series.sort原地操作,而 DataFrame.sort 返回一个新对象。

  • Series.order 返回一个新对象

  • 可以通过传递 by 关键字,使用 Series/DataFrame.sort_index排序。

  • Series/DataFrame.sortlevel 仅适用于 MultiIndex,用于按索引排序。

为了解决这些问题,我们改进了 API

  • 我们引入了一个新方法 DataFrame.sort_values(),它是 DataFrame.sort()Series.sort()Series.order() 的合并,用于处理按排序。

  • 现有的 Series.sort()Series.order()DataFrame.sort() 方法已被弃用,并将在未来版本中移除。

  • DataFrame.sort_index()by 参数已被弃用,并将在未来版本中移除。

  • 现有的 .sort_index() 方法将增加 level 关键字以支持按级别排序。

我们现在有两种明确且不重叠的排序方法。带 * 的项将显示 FutureWarning

排序

之前

替代方法

* Series.order()

Series.sort_values()

* Series.sort()

Series.sort_values(inplace=True)

* DataFrame.sort(columns=...)

DataFrame.sort_values(by=...)

索引排序

之前

替代方法

Series.sort_index()

Series.sort_index()

Series.sortlevel(level=...)

Series.sort_index(level=...)

DataFrame.sort_index()

DataFrame.sort_index()

DataFrame.sortlevel(level=...)

DataFrame.sort_index(level=...)

* DataFrame.sort()

DataFrame.sort_index()

我们还弃用并更改了两个类似 Series 的类 IndexCategorical 中的类似方法。

之前

替代方法

* Index.order()

Index.sort_values()

* Categorical.order()

Categorical.sort_values()

to_datetime 和 to_timedelta 的更改#

错误处理#

pd.to_datetime 的错误处理默认值已更改为 errors='raise'。在之前的版本中,它是 errors='ignore'。此外,coerce 参数已被弃用,取而代之的是 errors='coerce'。这意味着无效解析将引发异常,而不是像以前版本那样返回原始输入。(GH 10636)

之前行为

In [2]: pd.to_datetime(['2009-07-31', 'asd'])
Out[2]: array(['2009-07-31', 'asd'], dtype=object)

新行为

In [3]: pd.to_datetime(['2009-07-31', 'asd'])
ValueError: Unknown string format

当然,您也可以进行强制转换。

In [61]: pd.to_datetime(["2009-07-31", "asd"], errors="coerce")
Out[61]: DatetimeIndex(['2009-07-31', 'NaT'], dtype='datetime64[ns]', freq=None)

要保留以前的行为,您可以使用 errors='ignore'

In [4]: pd.to_datetime(["2009-07-31", "asd"], errors="ignore")
Out[4]: Index(['2009-07-31', 'asd'], dtype='object')

此外,pd.to_timedelta 获得了类似的 API,即 errors='raise'|'ignore'|'coerce',并且 coerce 关键字已被弃用,取而代之的是 errors='coerce'

一致的解析#

to_datetimeTimestampDatetimeIndex 的字符串解析已实现一致。(GH 7599)

在 v0.17.0 之前,Timestampto_datetime 可能会错误地使用今天的日期解析仅包含年份的日期时间字符串,否则 DatetimeIndex 会使用年初。对于某些 DatetimeIndex 可以解析的日期时间字符串类型(例如季度字符串),Timestampto_datetime 可能会引发 ValueError

之前行为

In [1]: pd.Timestamp('2012Q2')
Traceback
   ...
ValueError: Unable to parse 2012Q2

# Results in today's date.
In [2]: pd.Timestamp('2014')
Out [2]: 2014-08-12 00:00:00

v0.17.0 可以按如下方式解析它们。它也适用于 DatetimeIndex

新行为

In [62]: pd.Timestamp("2012Q2")
Out[62]: Timestamp('2012-04-01 00:00:00')

In [63]: pd.Timestamp("2014")
Out[63]: Timestamp('2014-01-01 00:00:00')

In [64]: pd.DatetimeIndex(["2012Q2", "2014"])
Out[64]: DatetimeIndex(['2012-04-01', '2014-01-01'], dtype='datetime64[ns]', freq=None)

注意

如果您想基于今天的日期执行计算,请使用 Timestamp.now()pandas.tseries.offsets

In [65]: import pandas.tseries.offsets as offsets

In [66]: pd.Timestamp.now()
Out[66]: Timestamp('2024-09-20 12:30:23.176994')

In [67]: pd.Timestamp.now() + offsets.DateOffset(years=1)
Out[67]: Timestamp('2025-09-20 12:30:23.177749')

Index 比较的更改#

Index 上的等于运算符行为应与 Series 类似 (GH 9947, GH 10637)

从 v0.17.0 开始,比较不同长度的 Index 对象将引发 ValueError。这与 Series 的行为保持一致。

之前行为

In [2]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5])
Out[2]: array([ True, False, False], dtype=bool)

In [3]: pd.Index([1, 2, 3]) == pd.Index([2])
Out[3]: array([False,  True, False], dtype=bool)

In [4]: pd.Index([1, 2, 3]) == pd.Index([1, 2])
Out[4]: False

新行为

In [8]: pd.Index([1, 2, 3]) == pd.Index([1, 4, 5])
Out[8]: array([ True, False, False], dtype=bool)

In [9]: pd.Index([1, 2, 3]) == pd.Index([2])
ValueError: Lengths must match to compare

In [10]: pd.Index([1, 2, 3]) == pd.Index([1, 2])
ValueError: Lengths must match to compare

请注意,这与 numpy 的行为不同,numpy 中的比较可以广播

In [68]: np.array([1, 2, 3]) == np.array([1])
Out[68]: array([ True, False, False])

或者如果无法广播则返回 False

In [11]: np.array([1, 2, 3]) == np.array([1, 2])
Out[11]: False

布尔比较与 None 的更改#

SeriesNone 的布尔比较现在等同于与 np.nan 比较,而不是引发 TypeError。(GH 1079)。

In [69]: s = pd.Series(range(3), dtype="float")

In [70]: s.iloc[1] = None

In [71]: s
Out[71]: 
0    0.0
1    NaN
2    2.0
Length: 3, dtype: float64

之前行为

In [5]: s == None
TypeError: Could not compare <type 'NoneType'> type with Series

新行为

In [72]: s == None
Out[72]: 
0    False
1    False
2    False
Length: 3, dtype: bool

通常您只想知道哪些值是 null。

In [73]: s.isnull()
Out[73]: 
0    False
1     True
2    False
Length: 3, dtype: bool

警告

对于这类比较,通常您会希望使用 isnull/notnull,因为 isnull/notnull 会告诉您哪些元素是 null。需要注意的是,nan's 不等于自身,但 None's 等于自身。请注意,pandas/numpy 利用了 np.nan != np.nan 这一事实,并将 None 视为 np.nan

In [74]: None == None
Out[74]: True

In [75]: np.nan == np.nan
Out[75]: False

HDFStore dropna 行为#

HDFStore 写入函数在使用 format='table' 时的默认行为是保留所有缺失值的行。之前,其行为是删除除索引外的所有缺失值的行。可以使用 dropna=True 选项复制以前的行为。(GH 9382)

之前行为

In [76]: df_with_missing = pd.DataFrame(
   ....:     {"col1": [0, np.nan, 2], "col2": [1, np.nan, np.nan]}
   ....: )
   ....: 

In [77]: df_with_missing
Out[77]: 
   col1  col2
0   0.0   1.0
1   NaN   NaN
2   2.0   NaN

[3 rows x 2 columns]
In [27]:
df_with_missing.to_hdf('file.h5',
                       key='df_with_missing',
                       format='table',
                       mode='w')

In [28]: pd.read_hdf('file.h5', 'df_with_missing')

Out [28]:
      col1  col2
  0     0     1
  2     2   NaN

新行为

In [78]: df_with_missing.to_hdf("file.h5", key="df_with_missing", format="table", mode="w")

In [79]: pd.read_hdf("file.h5", "df_with_missing")
Out[79]: 
   col1  col2
0   0.0   1.0
1   NaN   NaN
2   2.0   NaN

[3 rows x 2 columns]

更多详情请参阅文档

display.precision 选项的更改#

display.precision 选项已明确指的是小数点位数 (GH 10451)。

早期版本的 pandas 会将浮点数格式化为比 display.precision 中的值少一位小数。

In [1]: pd.set_option('display.precision', 2)

In [2]: pd.DataFrame({'x': [123.456789]})
Out[2]:
       x
0  123.5

如果将精度解释为“有效数字”,这对于科学计数法有效,但相同的解释对于标准格式的值无效。这也与 numpy 处理格式的方式不一致。

未来,display.precision 的值将直接控制小数点后的位数,无论是常规格式还是科学计数法,这类似于 numpy 的 precision 打印选项的工作方式。

In [80]: pd.set_option("display.precision", 2)

In [81]: pd.DataFrame({"x": [123.456789]})
Out[81]: 
        x
0  123.46

[1 rows x 1 columns]

为了保留与先前版本相同的输出行为,display.precision 的默认值已从 7 减小到 6

Categorical.unique 的更改#

Categorical.unique 现在返回新的 Categoricals,其 categoriescodes 是唯一的,而不是返回 np.array (GH 10508)

  • 无序类别:values 和 categories 按出现顺序排序。

  • 有序类别:values 按出现顺序排序,categories 保留现有顺序。

In [82]: cat = pd.Categorical(["C", "A", "B", "C"], categories=["A", "B", "C"], ordered=True)

In [83]: cat
Out[83]: 
['C', 'A', 'B', 'C']
Categories (3, object): ['A' < 'B' < 'C']

In [84]: cat.unique()
Out[84]: 
['C', 'A', 'B']
Categories (3, object): ['A' < 'B' < 'C']

In [85]: cat = pd.Categorical(["C", "A", "B", "C"], categories=["A", "B", "C"])

In [86]: cat
Out[86]: 
['C', 'A', 'B', 'C']
Categories (3, object): ['A', 'B', 'C']

In [87]: cat.unique()
Out[87]: 
['C', 'A', 'B']
Categories (3, object): ['A', 'B', 'C']

在解析器中将 bool 作为 header 传递的更改#

在早期版本的 pandas 中,如果将布尔值传递给 read_csvread_excelread_htmlheader 参数,它会被隐式转换为整数,导致 False 对应 header=0True 对应 header=1 (GH 6113)

现在,将 bool 输入给 header 将引发 TypeError

In [29]: df = pd.read_csv('data.csv', header=False)
TypeError: Passing a bool to header is invalid. Use header=None for no header or
header=int or list-like of ints to specify the row(s) making up the column names

其他 API 更改#

  • 使用 subplots=True 的 Line 图和 kde 图现在使用默认颜色,而不是全部黑色。指定 color='k' 可将所有线条绘制为黑色 (GH 9894)

  • 在具有 categorical dtype 的 Series 上调用 .value_counts() 方法现在返回具有 CategoricalIndex 的 Series (GH 10704)

  • pandas 对象子类的元数据属性现在将被序列化 (GH 10553)。

  • 使用 Categoricalgroupby 遵循与上述 Categorical.unique 相同的规则 (GH 10508)

  • 之前,使用 complex64 dtype 数组构建 DataFrame 意味着相应的列会自动升级到 complex128 dtype。pandas 现在将保留复杂数据输入的 itemsize (GH 10952)

  • 一些数值归约运算符在包含字符串和数字的对象类型上会返回 ValueError,而不是 TypeError (GH 11131)

  • 现在将目前不支持的 chunksize 参数传递给 read_excelExcelFile.parse 将引发 NotImplementedError (GH 8011)

  • 允许将 ExcelFile 对象传递给 read_excel (GH 11198)

  • 如果 self 和输入对象的 freq 都为 None,则 DatetimeIndex.union 不会推断 freq (GH 11086)

  • NaT 的方法现在要么引发 ValueError,要么返回 np.nanNaT (GH 9513)

    行为

    方法

    返回 np.nan

    weekday, isoweekday

    返回 NaT

    date, now, replace, to_datetime, today

    返回 np.datetime64('NaT')

    to_datetime64 (未更改)

    引发 ValueError

    所有其他公共方法(名称不以下划线开头)

弃用#

  • 对于 Series,以下索引函数已被弃用 (GH 10177)。

    已弃用函数

    替代方法

    替代方法

    .irow(i)

    .iloc[i].iat[i]

    .irow(i)

    .iget(i)

    .irow(i)

  • .iget_value(i)

    已弃用函数

    替代方法

    替代方法

    对于 DataFrame,以下索引函数已被弃用 (GH 10177)。

    .iget_value(i, j)

    .iloc[i, j].iat[i, j]

    .icol(j)

    .iloc[:, j]

注意

这些索引函数自 0.11.0 版本以来已在文档中被弃用。

  • 弃用了 Categorical.name 以使 Categorical 更像 numpy.ndarray。请改用 Series(cat, name="whatever") (GH 10482)。

  • Categoricalcategories 中设置缺失值 (NaN) 将发出警告 (GH 10748)。您仍然可以在 values 中拥有缺失值。

  • drop_duplicatesduplicatedtake_last 关键字已被弃用,取而代之的是 keep。(GH 6511, GH 8505)

  • Series.nsmallestnlargesttake_last 关键字已被弃用,取而代之的是 keep。(GH 10792)

  • DataFrame.combineAddDataFrame.combineMult 已被弃用。它们可以很容易地通过使用 addmul 方法替换:DataFrame.add(other, fill_value=0)DataFrame.mul(other, fill_value=1.) (GH 10735)。

  • TimeSeries 已弃用,推荐使用 Series(请注意,自 0.13.0 版本以来这已是别名),(GH 10890)

  • SparsePanel 已弃用,将在未来的版本中移除 (GH 11157)。

  • Series.is_time_series 已弃用,推荐使用 Series.index.is_all_dates (GH 11135)

  • 旧版偏移量(例如 'A@JAN')已弃用(请注意,自 0.8.0 版本以来这已是别名)(GH 10878)

  • WidePanel 已弃用,推荐使用 PanelLongPanel 已弃用,推荐使用 DataFrame(请注意,自 0.11.0 版本之前这已是别名),(GH 10892)

  • DataFrame.convert_objects 已弃用,推荐使用类型特定的函数 pd.to_datetimepd.to_timestamppd.to_numeric(0.17.0 新增)(GH 11133)。

移除先前版本的弃用/变更#

  • 移除 Series.order()Series.sort() 中的 na_last 参数,推荐使用 na_position。(GH 5231)

  • 移除 .describe() 中的 percentile_width,推荐使用 percentiles。(GH 7088)

  • 移除 DataFrame.to_string() 中的 colSpace 参数,推荐使用 col_space,约在 0.8.0 版本时。

  • 移除时间序列自动广播 (GH 2304)

    In [88]: np.random.seed(1234)
    
    In [89]: df = pd.DataFrame(
       ....:     np.random.randn(5, 2),
       ....:     columns=list("AB"),
       ....:     index=pd.date_range("2013-01-01", periods=5),
       ....: )
       ....: 
    
    In [90]: df
    Out[90]: 
                       A         B
    2013-01-01  0.471435 -1.190976
    2013-01-02  1.432707 -0.312652
    2013-01-03 -0.720589  0.887163
    2013-01-04  0.859588 -0.636524
    2013-01-05  0.015696 -2.242685
    
    [5 rows x 2 columns]
    

    之前

    In [3]: df + df.A
    FutureWarning: TimeSeries broadcasting along DataFrame index by default is deprecated.
    Please use DataFrame.<op> to explicitly broadcast arithmetic operations along the index
    
    Out[3]:
                        A         B
    2013-01-01  0.942870 -0.719541
    2013-01-02  2.865414  1.120055
    2013-01-03 -1.441177  0.166574
    2013-01-04  1.719177  0.223065
    2013-01-05  0.031393 -2.226989
    

    当前

    In [91]: df.add(df.A, axis="index")
    Out[91]: 
                       A         B
    2013-01-01  0.942870 -0.719541
    2013-01-02  2.865414  1.120055
    2013-01-03 -1.441177  0.166574
    2013-01-04  1.719177  0.223065
    2013-01-05  0.031393 -2.226989
    
    [5 rows x 2 columns]
    
  • 移除 HDFStore.put/append 中的 table 关键字,推荐使用 format= (GH 4645)

  • 移除 read_excel/ExcelFile 中未使用的 kind 参数 (GH 4712)

  • 移除 pd.read_html 中未使用的 infer_type 关键字 (GH 4770, GH 7032)

  • 移除 Series.tshift/shift 中的 offsettimeRule 关键字,推荐使用 freq (GH 4853, GH 4864)

  • 移除 pd.load/pd.save 别名,推荐使用 pd.to_pickle/pd.read_pickle (GH 3787)

性能改进#

  • 添加了对使用 Air Speed Velocity 库进行基准测试的开发支持 (GH 8361)

  • 为替代的 ExcelWriter 引擎和读取 Excel 文件添加了 vbench 基准测试 (GH 7171)

  • 改进了 Categorical.value_counts 的性能 (GH 10804)

  • 改进了 SeriesGroupBy.nuniqueSeriesGroupBy.value_countsSeriesGroupby.transform 的性能 (GH 10820, GH 11077)

  • 改进了整数 dtype 的 DataFrame.drop_duplicates 的性能 (GH 10917)

  • 改进了宽 DataFrame 的 DataFrame.duplicated 的性能。(GH 10161, GH 11180)

  • timedelta 字符串解析性能提升 4 倍 (GH 6755, GH 10426)

  • timedelta64datetime64 操作性能提升 8 倍 (GH 6755)

  • 使用 slicer 对 MultiIndex 进行索引的性能显著改进 (GH 10287)

  • 使用列表状输入对 iloc 进行索引性能提升 8 倍 (GH 10791)

  • 改进了日期时间类/整数 Series 的 Series.isin 的性能 (GH 10287)

  • 当分类相同时,concat Categoricals 的性能提升 20 倍 (GH 10587)

  • 当指定的格式字符串为 ISO8601 时,改进了 to_datetime 的性能 (GH 10178)

  • 浮点 dtype 的 Series.value_counts 性能提升 2 倍 (GH 10821)

  • 当日期组成部分没有零填充时,在 to_datetime 中启用 infer_datetime_format (GH 11142)

  • 从嵌套字典构造 DataFrame 的回归问题,源于 0.16.1 版本 (GH 11084)

  • 改进了 DateOffsetSeriesDatetimeIndex 的加减操作性能 (GH 10744, GH 11205)

错误修复#

  • 由于溢出导致 timedelta64[ns].mean() 计算不正确错误 (GH 9442)

  • 在旧版 numpies 上使用 .isin 的错误 (GH 11232)

  • DataFrame.to_html(index=False) 渲染不必要的 name 行错误 (GH 10344)

  • DataFrame.to_latex() 中无法传递 column_format 参数的错误 (GH 9402)

  • 使用 NaT 进行本地化时 DatetimeIndex 的错误 (GH 10477)

  • Series.dt 操作中未能保留元数据的错误 (GH 10477)

  • 在其他情况下无效的 to_datetime 构造中未能保留 NaT 的错误 (GH 10477)

  • 当函数返回分类序列时,DataFrame.apply 的错误。(GH 9573)

  • 提供了无效日期和格式时 to_datetime 的错误 (GH 10154)

  • Index.drop_duplicates 丢弃名称的错误 (GH 10115)

  • Series.quantile 丢弃名称的错误 (GH 10881)

  • 当在索引具有频率的空 Series 上设置值时,pd.Series 的错误。(GH 10193)

  • pd.Series.interpolate 使用无效 order 关键字值时的错误。(GH 10633)

  • 当颜色名称由多个字符指定时,DataFrame.plot 引发 ValueError 的错误 (GH 10387)

  • 使用包含混合元组列表构造 Index 的错误 (GH 10697)

  • 当索引包含 NaT 时,DataFrame.reset_index 的错误。(GH 10388)

  • 当工作表为空时,ExcelReader 的错误 (GH 6403)

  • BinGrouper.group_info 返回值与基类不兼容的错误 (GH 10914)

  • DataFrame.pop 和后续原地操作中清除缓存的错误 (GH 10912)

  • 使用混合整数 Index 进行索引时导致 ImportError 的错误 (GH 10610)

  • 当索引包含空值时,Series.count 的错误 (GH 10946)

  • 序列化非规则频率 DatetimeIndex 的错误 (GH 11002)

  • 当 DataFrame 具有对称形状时,DataFrame.where 未遵守 axis 参数的错误。(GH 9736)

  • Table.select_column 中名称未保留的错误 (GH 10392)

  • offsets.generate_rangestartend 精度高于 offset 的错误 (GH 9907)

  • pd.rolling_* 输出中会丢失 Series.name 的错误 (GH 10565)

  • 当索引或列不唯一时,stack 的错误。(GH 10417)

  • 当轴包含 MultiIndex 时设置 Panel 的错误 (GH 10360)

  • USFederalHolidayCalendarUSMemorialDayUSMartinLutherKingJr 不正确的错误 (GH 10278GH 9760)

  • .sample() 中返回对象如果被设置会产生不必要的 SettingWithCopyWarning 警告的错误 (GH 10738)

  • .sample() 中将作为 Series 传递的权重在按位置处理前未沿轴对齐,如果权重索引与采样对象未对齐,可能导致问题。(GH 10738)

  • 已修复的回归问题(详见 (GH 9311, GH 6620, GH 9345)),该问题在使用某些聚合器对日期时间类进行 groupby 时会将其转换为浮点数 (GH 10979)

  • 使用 axis=1inplace=TrueDataFrame.interpolate 的错误 (GH 10395)

  • 指定多个列作为主键时 io.sql.get_schema 的错误。(GH 10385)。

  • 使用日期时间类 Categorical 进行 groupby(sort=False) 时引发 ValueError 的错误 (GH 10505)

  • 使用 filter()groupby(axis=1) 进行操作时抛出 IndexError 的错误 (GH 11041)

  • 在大端序构建上运行 test_categorical 的错误 (GH 10425)

  • Series.shiftDataFrame.shift 不支持分类数据的错误 (GH 9416)

  • 使用分类 SeriesSeries.map 引发 AttributeError 的错误 (GH 10324)

  • MultiIndex.get_level_values 包含 Categorical 时引发 AttributeError 的错误 (GH 10460)

  • pd.get_dummies 使用 sparse=True 时未返回 SparseDataFrame 的错误 (GH 10531)

  • Index 子类型(例如 PeriodIndex)在使用 .drop.insert 方法时未返回自身类型的错误 (GH 10620)

  • right 数组为空时,algos.outer_join_indexer 的错误 (GH 10618)

  • 当按多个键进行分组(其中一个键是日期时间类)时,filter(源于 0.16.0 的回归问题)和 transform 的错误 (GH 10114)

  • to_datetimeto_timedelta 导致 Index 名称丢失的错误 (GH 10875)

  • 当存在仅包含 NaNs 的列时,len(DataFrame.groupby) 导致 IndexError 的错误 (GH 11016)

  • 对空 Series 重采样时导致段错误的错误 (GH 10228)

  • DatetimeIndexPeriodIndex.value_counts 重置结果的名称,但保留在结果的 Index 中的错误。(GH 10150)

  • pd.eval 使用 numexpr 引擎时将包含 1 个元素的 numpy 数组强制转换为标量的错误 (GH 10546)

  • 当列 dtype 为 category 时,pd.concat 使用 axis=0 的错误 (GH 10177)

  • read_msgpack 未始终检查输入类型的错误 (GH 10369, GH 10630)

  • pd.read_csv 使用 kwargs index_col=Falseindex_col=['a', 'b']dtype 时的错误 (GH 10413, GH 10467, GH 10577)

  • Series.from_csv 使用 header kwarg 时未设置 Series.nameSeries.index.name 的错误 (GH 10483)

  • groupby.var 对于小的浮点值计算方差不准确的错误 (GH 10448)

  • Series.plot(kind='hist') Y 轴标签信息不足的错误 (GH 10485)

  • read_csv 使用生成 uint8 类型转换器的错误 (GH 9266)

  • 时间序列折线图和面积图导致内存泄漏的错误 (GH 9003)

  • 当右侧是 DataFrame 时,设置沿主轴或副轴切片的 Panel 的错误 (GH 11014)

  • Panel 的操作符函数(例如 .add)未实现时返回 None 而未引发 NotImplementedError 的错误 (GH 7692)

  • subplots=True 时,折线图和 kde 图无法接受多种颜色的错误 (GH 9894)

  • 当颜色名称由多个字符指定时,DataFrame.plot 引发 ValueError 的错误 (GH 10387)

  • 带有 MultiIndexSeries 的左、右 align 可能反转的错误 (GH 10665)

  • 带有 MultiIndex 的左、右 join 可能反转的错误 (GH 10741)

  • 读取文件中 columns 设置了不同顺序时 read_stata 的错误 (GH 10757)

  • 当分类包含 tzPeriod 时,Categorical 可能表示不正确的错误 (GH 10713)

  • Categorical.__iter__ 可能未返回正确的 datetimePeriod 的错误 (GH 10713)

  • 对包含 PeriodIndex 的对象使用 PeriodIndex 进行索引的错误 (GH 4125)

  • read_csv 使用 engine='c' 时,由注释、空行等开头的 EOF 未正确处理的错误 (GH 10728, GH 10548)

  • 通过 DataReader 读取“famafrench”数据时,由于网站 URL 更改导致 HTTP 404 错误的错误。(GH 10591)。

  • read_msgpack 解码的 DataFrame 具有重复列名的错误 (GH 9618)

  • io.common.get_filepath_or_buffer 的错误,该错误导致在用户对 bucket 中的某些 key 没有读取权限时读取有效 S3 文件失败 (GH 10604)

  • 使用 Python datetime.date 和 numpy datetime64 对时间戳列进行矢量化设置的错误 (GH 10408, GH 10412)

  • Index.take 可能添加不必要的 freq 属性的错误 (GH 10791)

  • 与空 DataFrame 合并时 merge 可能引发 IndexError 的错误 (GH 10824)

  • to_latex 对一些已文档的参数使用意料之外的关键字参数的错误 (GH 10888)

  • 对大型 DataFrame 进行索引时未捕获 IndexError 的错误 (GH 10645GH 10692)

  • 文件仅包含一行头部时,read_csv 使用 nrowschunksize 参数的错误 (GH 9535)

  • 在存在替代编码时,HDF5 中 category 类型序列化的错误。(GH 10366)

  • 使用字符串 dtype 构造空 DataFrame 时 pd.DataFrame 的错误 (GH 9428)

  • 当 DataFrame 未合并时,pd.DataFrame.diff 的错误 (GH 10907)

  • datetime64timedelta64 dtype 数组使用 pd.unique 时返回 object dtype 数组而非原始 dtype 数组的错误 (GH 9431)

  • 从 0s 切片时 Timedelta 引发错误的错误 (GH 10583)

  • DatetimeIndex.takeTimedeltaIndex.take 对无效索引可能未引发 IndexError 的错误 (GH 10295)

  • Series([np.nan]).astype('M8[ms]') 的错误,现在已修复为返回 Series([pd.NaT]) (GH 10747)

  • PeriodIndex.order 重置 freq 的错误 (GH 10295)

  • freq 以纳秒为单位整除 end 时,date_range 的错误 (GH 10885)

  • iloc 允许使用负整数访问超出 Series 边界内存的错误 (GH 10779)

  • read_msgpack 未遵守编码的错误 (GH 10581)

  • 使用包含适当负整数的列表对 iloc 进行索引时无法访问第一个索引的错误 (GH 10547, GH 10779)

  • TimedeltaIndex 格式化程序导致尝试使用 to_csv 保存包含 TimedeltaIndexDataFrame 时出错的错误 (GH 10833)

  • 处理 Series 切片时 DataFrame.where 的错误 (GH 10218, GH 9558)

  • 当 Bigquery 返回零行时 pd.read_gbq 抛出 ValueError 的错误 (GH 10273)

  • to_json 在序列化 0 阶 ndarray 时导致段错误的错误 (GH 9576)

  • GridSpec 上绘图时,绘图函数可能引发 IndexError 的错误 (GH 10819)

  • 绘图结果可能显示不必要的次刻度标签的错误 (GH 10657)

  • groupby 对包含 NaTDataFrame 进行聚合计算不正确的错误(例如 firstlastmin)。(GH 10590, GH 11010)

  • 构造 DataFrame 时,传递只包含标量值的字典并指定列却未引发错误的错误 (GH 10856)

  • .var() 中的错误导致高度相似的值出现四舍五入误差 (GH 10242)

  • DataFrame.plot(subplots=True) 中的错误导致带有重复列时输出不正确的结果 (GH 10962)

  • Index 中的算术运算可能导致不正确的类 (GH 10638)

  • date_range 中的错误导致当 freq 为负值的年、季度和月时结果为空 (GH 11018)

  • DatetimeIndex 中的错误导致无法推断负值的 freq (GH 11018)

  • 移除了部分已弃用的 numpy 比较操作的使用,主要在测试中。(GH 10569)

  • Index 中的错误导致 dtype 可能未正确应用 (GH 11017)

  • io.gbq 中的错误导致在测试最低 google api 客户端版本时出现问题 (GH 10652)

  • 从嵌套的 dict 使用 timedelta 键构建 DataFrame 时出现的错误 (GH 11129)

  • .fillna 中当数据包含 datetime dtype 时可能引发 TypeError 错误 (GH 7095, GH 11153)

  • .groupby 中当用于分组的键的数量与索引长度相同时出现的错误 (GH 11185)

  • convert_objects 中当所有值都为 null 且 coerce 时,转换后的值可能不会被返回的错误 (GH 9589)

  • convert_objectscopy 关键字未被遵守的错误 (GH 9589)

贡献者#

共有 112 位贡献者为本次发布贡献了补丁。名字旁带有“+”号的人是首次贡献补丁。

  • Alex Rothberg

  • Andrea Bedini +

  • Andrew Rosenfeld

  • Andy Hayden

  • Andy Li +

  • Anthonios Partheniou +

  • Artemy Kolchinsky

  • Bernard Willers

  • Charlie Clark +

  • Chris +

  • Chris Whelan

  • Christoph Gohlke +

  • Christopher Whelan

  • Clark Fitzgerald

  • Clearfield Christopher +

  • Dan Ringwalt +

  • Daniel Ni +

  • Data & Code Expert Experimenting with Code on Data +

  • David Cottrell

  • David John Gagne +

  • David Kelly +

  • ETF +

  • Eduardo Schettino +

  • Egor +

  • Egor Panfilov +

  • Evan Wright

  • Frank Pinter +

  • Gabriel Araujo +

  • Garrett-R

  • Gianluca Rossi +

  • Guillaume Gay

  • Guillaume Poulin

  • Harsh Nisar +

  • Ian Henriksen +

  • Ian Hoegen +

  • Jaidev Deshpande +

  • Jan Rudolph +

  • Jan Schulz

  • Jason Swails +

  • Jeff Reback

  • Jonas Buyl +

  • Joris Van den Bossche

  • Joris Vankerschaver +

  • Josh Levy-Kramer +

  • Julien Danjou

  • Ka Wo Chen

  • Karrie Kehoe +

  • Kelsey Jordahl

  • Kerby Shedden

  • Kevin Sheppard

  • Lars Buitinck

  • Leif Johnson +

  • Luis Ortiz +

  • Mac +

  • Matt Gambogi +

  • Matt Savoie +

  • Matthew Gilbert +

  • Maximilian Roos +

  • Michelangelo D’Agostino +

  • Mortada Mehyar

  • Nick Eubank

  • Nipun Batra

  • Ondřej Čertík

  • Phillip Cloud

  • Pratap Vardhan +

  • Rafal Skolasinski +

  • Richard Lewis +

  • Rinoc Johnson +

  • Rob Levy

  • Robert Gieseke

  • Safia Abdalla +

  • Samuel Denny +

  • Saumitra Shahapure +

  • Sebastian Pölsterl +

  • Sebastian Rubbert +

  • Sheppard, Kevin +

  • Sinhrks

  • Siu Kwan Lam +

  • Skipper Seabold

  • Spencer Carrucciu +

  • Stephan Hoyer

  • Stephen Hoover +

  • Stephen Pascoe +

  • Terry Santegoeds +

  • Thomas Grainger

  • Tjerk Santegoeds +

  • Tom Augspurger

  • Vincent Davis +

  • Winterflower +

  • Yaroslav Halchenko

  • Yuan Tang (Terry) +

  • agijsberts

  • ajcr +

  • behzad nouri

  • cel4

  • chris-b1 +

  • cyrusmaher +

  • davidovitch +

  • ganego +

  • jreback

  • juricast +

  • larvian +

  • maximilianr +

  • msund +

  • rekcahpassyla

  • robertzk +

  • scls19fr

  • seth-p

  • sinhrks

  • springcoil +

  • terrytangyuan +

  • tzinckgraf +