版本 0.17.1 (2015 年 11 月 21 日)#
注意
我們自豪地宣佈 pandas 已成為 (NumFOCUS 組織) 的贊助專案。這將有助於確保 pandas 作為世界一流的開源專案開發的成功。
這是繼 0.17.0 之後的次要錯誤修復版本,其中包含大量錯誤修復,以及一些新功能、增強功能和效能改進。我們建議所有使用者升級到此版本。
亮點包括
支援條件 HTML 格式,請參閱 此處
在 csv 讀取器和其他操作中釋放 GIL,請參閱 此處
修復了 0.16.2 版本中 DataFrame.drop_duplicates 的迴歸,該回歸導致整數值結果不正確(GH 11376)
新功能#
條件 HTML 格式#
警告
這是一項新功能,並且正在積極開發中。我們將在未來的版本中新增功能,並可能進行重大更改。歡迎在 GH 11610 中提供反饋。
我們添加了條件 HTML 格式的實驗性支援:根據資料對 DataFrame 進行視覺樣式化。樣式是透過 HTML 和 CSS 實現的。透過 pandas.DataFrame.style 屬性訪問樣式器類,這是一個附加了資料的 Styler 例項。
這裡有一個快速示例
In [1]: np.random.seed(123) In [2]: df = pd.DataFrame(np.random.randn(10, 5), columns=list("abcde")) In [3]: html = df.style.background_gradient(cmap="viridis", low=0.5)
我們可以渲染 HTML 以獲得下表。
| a | b | c | d | e | |
|---|---|---|---|---|---|
| 0 | -1.085631 | 0.997345 | 0.282978 | -1.506295 | -0.5786 |
| 1 | 1.651437 | -2.426679 | -0.428913 | 1.265936 | -0.86674 |
| 2 | -0.678886 | -0.094709 | 1.49139 | -0.638902 | -0.443982 |
| 3 | -0.434351 | 2.20593 | 2.186786 | 1.004054 | 0.386186 |
| 4 | 0.737369 | 1.490732 | -0.935834 | 1.175829 | -1.253881 |
| 5 | -0.637752 | 0.907105 | -1.428681 | -0.140069 | -0.861755 |
| 6 | -0.255619 | -2.798589 | -1.771533 | -0.699877 | 0.927462 |
| 7 | -0.173636 | 0.002846 | 0.688223 | -0.879536 | 0.283627 |
| 8 | -0.805367 | -1.727669 | -0.3909 | 0.573806 | 0.338589 |
| 9 | -0.01183 | 2.392365 | 0.412912 | 0.978736 | 2.238143 |
增強功能#
DatetimeIndex現在支援使用astype(str)轉換為字串(GH 10442)在
pandas.DataFrame.to_csv()中支援compression(gzip/bz2)(GH 7615)pd.read_* 函式現在也可以接受
pathlib.Path或py:py._path.local.LocalPath物件作為filepath_or_buffer引數。(GH 11033)-DataFrame和Series函式.to_csv()、.to_html()和.to_latex()現在可以處理以波浪號開頭(例如~/Documents/)的路徑(GH 11438)如果未提供列,
DataFrame現在將namedtuple的欄位用作列(GH 11181)當可能時,
DataFrame.itertuples()現在返回namedtuple物件。(GH 11269,GH 11625)為平行座標圖添加了
axvlines_kwds(GH 10709)提供
.info()和.memory_usage()的選項,以提供記憶體消耗的深度自省。請注意,這計算起來可能很昂貴,因此它是一個可選引數。(GH 11595)In [4]: df = pd.DataFrame({"A": ["foo"] * 1000}) # noqa: F821 In [5]: df["B"] = df["A"].astype("category") # shows the '+' as we have object dtypes In [6]: df.info() <class 'pandas.DataFrame'> RangeIndex: 1000 entries, 0 to 999 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 A 1000 non-null str 1 B 1000 non-null category dtypes: category(1), str(1) memory usage: 11.9 KB # we have an accurate memory assessment (but can be expensive to compute this) In [7]: df.info(memory_usage="deep") <class 'pandas.DataFrame'> RangeIndex: 1000 entries, 0 to 999 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 A 1000 non-null str 1 B 1000 non-null category dtypes: category(1), str(1) memory usage: 11.9 KB
Index現在有一個fillna方法(GH 10089)In [8]: pd.Index([1, np.nan, 3]).fillna(2) Out[8]: Index([1.0, 2.0, 3.0], dtype='float64')
category型別的 Series 現在提供.str.<...>和.dt.<...>訪問器方法/屬性,如果類別屬於該型別。(GH 10661)In [9]: s = pd.Series(list("aabb")).astype("category") In [10]: s Out[10]: 0 a 1 a 2 b 3 b Length: 4, dtype: category Categories (2, str): ['a', 'b'] In [11]: s.str.contains("a") Out[11]: 0 True 1 True 2 False 3 False Length: 4, dtype: bool In [12]: date = pd.Series(pd.date_range("1/1/2015", periods=5)).astype("category") In [13]: date Out[13]: 0 2015-01-01 1 2015-01-02 2 2015-01-03 3 2015-01-04 4 2015-01-05 Length: 5, dtype: category Categories (5, datetime64[us]): [2015-01-01, 2015-01-02, 2015-01-03, 2015-01-04, 2015-01-05] In [14]: date.dt.day Out[14]: 0 1 1 2 2 3 3 4 4 5 Length: 5, dtype: int32
pivot_table現在有一個margins_name引數,因此您可以使用除預設值“All”之外的其他名稱(GH 3335)使用固定的 HDF5 儲存實現
datetime64[ns, tz]dtypes 的匯出(GH 11411)對集合的漂亮列印(例如,在 DataFrame 單元格中)現在使用集合字面量語法(
{x, y}),而不是舊版 Python 語法(set([x, y]))(GH 11215)改進了
pandas.io.gbq.to_gbq()在流式插入失敗時(GH 11285)以及 DataFrame 與目標表模式不匹配時(GH 11359)的錯誤訊息。
API 更改#
對不支援的索引型別的
Index.shift丟擲NotImplementedError(GH 8038)對
datetime64和timedelta64dtyped Series 進行的min和max歸約現在結果為NaT而不是nan(GH 11245)。使用 null 鍵進行索引將丟擲
TypeError,而不是ValueError(GH 11356)Series.ptp現在預設將忽略缺失值(GH 11163)
棄用#
效能改進#
在索引上排序之前檢查單調性(GH 11080)
當其 dtype 無法包含
NaN時,Series.dropna效能得到改進(GH 11159)釋放大多數日期時間欄位操作(例如
DatetimeIndex.year、Series.dt.year)、規範化以及與Period的相互轉換、DatetimeIndex.to_period和PeriodIndex.to_timestamp的 GIL(GH 11263)在某些滾動演算法中釋放 GIL:
rolling_median、rolling_mean、rolling_max、rolling_min、rolling_var、rolling_kurt、rolling_skew(GH 11450)在
read_csv、read_table中讀取和解析文字檔案時釋放 GIL(GH 11272)改進了
rolling_median的效能(GH 11450)改進了
to_excel的效能(GH 11352)Categorical 類別 repr 中的效能 bug,它在截斷顯示之前渲染了字串(GH 11305)
Categorical.remove_unused_categories 的效能改進(GH 11643)。
改進了具有空資料和
DatetimeIndex的Series建構函式的效能(GH 11433)改進了具有 groupby 的
shift、cumprod和cumsum的效能(GH 4095)
Bug 修復#
SparseArray.__iter__()在 Python 3.5 中現在不會導致PendingDeprecationWarning(GH 11622)0.16.2 版本中關於長浮點數/NaN 輸出格式的迴歸,已在(GH 11302)中恢復
Series.sort_index()現在可以正確處理inplace選項(GH 11402)在 PyPi 上構建時,.c 檔案錯誤分發,當讀取浮點數 CSV 並傳遞
na_values=<a scalar>時會引發異常(GH 11374).to_latex() 輸出的 bug,當索引有名時損壞(GH 10660)
HDFStore.append 的 bug,當字串的編碼長度超過最大未編碼長度時(GH 11234)
合併
datetime64[ns, tz]dtypes 時的 bug(GH 11405)在使用 where 子句將 numpy 標量進行比較時,HDFStore.select 的 bug(GH 11283)
使用 MultiIndex 索引器時,DataFrame.ix 的 bug(GH 11372)
date_range 在端點模糊時出錯(GH 11626)
阻止向訪問器
.str、.dt和.cat新增新屬性。由於無法檢索此類值,因此在設定時會出錯。(GH 10673)在具有模糊時間和
.dt訪問器進行時區轉換時的 bug(GH 11295)使用模糊時間索引時的輸出格式 bug(GH 11619)
Series 與 list-like 進行比較時的 bug(GH 11339)
使用
datetime64[ns, tz]和不相容的 to_replace 進行DataFrame.replace時的 bug(GH 11326,GH 11153)isnull 中的 bug,其中
numpy.array中的numpy.datetime64('NaT')未被確定為 null(GH 11206)使用混合整數 Index 進行列表式索引時的 bug(GH 11320)
當索引為
Categoricaldtype 時,pivot_table 使用margins=True的 bug(GH 10993)DataFrame.plot 無法使用十六進位制字串顏色(GH 10299)
0.16.2 版本中 DataFrame.drop_duplicates 的迴歸,導致整數值結果不正確(GH 11376)
pd.eval 中列表中的一元運算子出錯的 bug(GH 11235)
describe() 在丟棄分層索引的列名時的 bug(GH 11517)
DataFrame.pct_change() 未將
axis關鍵字傳遞到.fillna方法的 bug(GH 11150)當
columns引數傳遞了整數和字串混合的列名時,.to_csv() 中的 bug(GH 11637)使用
range進行索引時的 bug(GH 11652)在設定列時,numpy 標量的推斷和保留 dtype 的 bug(GH 11638)
使用 Unicode 列名時,to_sql 出現
UnicodeEncodeError的 bug(GH 11431)。修復了設定
plot中xticks的迴歸(GH 11529)。holiday.dates 中的 bug,其中可將觀察規則應用於節假日,以及文件增強(GH 11477,GH 11533)
當
header=False時,DataFrame.to_latex() 產生額外規則的 bug(GH 7124)當 func 返回包含新日期時間列的
Series時,df.groupby(...).apply(func) 中的 bug(GH 11324)當要載入的檔案很大時,pandas.json 中的 bug(GH 11344)
修復了阻止構造
datetime64[ns, tz]dtype 的空 Series 的 bug(GH 11245)。read_excel 在處理包含整數的 MultiIndex 時的 bug(GH 11317)
to_excel 與 openpyxl 2.2+ 和合並時的 bug(GH 11408)
當資料中只有日期時間時,DataFrame.to_dict() 返回
np.datetime64物件而不是Timestamp的 bug(GH 11327)當計算包含布林列和非布林列的 DataFrame 的 Kendall 相關性時,DataFrame.corr() 丟擲異常的 bug(GH 11560)
FreeBSD 10+ 上 C
inline函式引起的連結時錯誤(使用clang)的 bug(GH 10510)DataFrame.to_csv 在傳遞格式化
MultiIndexes的引數(包括date_format)時的 bug(GH 7791)使用
how='right'進行DataFrame.join()時丟擲TypeError的 bug(GH 11519)當空列表作為結果時,Series.quantile 的 bug 導致
Index具有objectdtype(GH 11588)當合並結果為空時,pd.merge 導致空
Int64Index而不是Index(dtype=object)的 bug(GH 11588)當存在
NaN值時,Categorical.remove_unused_categories 中的 bug(GH 11599)DataFrame.to_sparse() 丟失 MultiIndexes 列名的 bug(GH 11600)
當具有非唯一列索引時,DataFrame.round() 導致 fatal Python 錯誤的 bug(GH 11611)
當
decimals是一個非唯一索引的 Series 時,DataFrame.round() 產生額外列的 bug(GH 11618)
貢獻者#
共有 63 人為此釋出貢獻了補丁。名字旁邊帶有“+”的人是第一次貢獻補丁。
Aleksandr Drozd +
Alex Chase +
Anthonios Partheniou
BrenBarn +
Brian J. McGuirk +
Chris
Christian Berendt +
Christian Perez +
Cody Piersall +
Data & Code Expert Experimenting with Code on Data
DrIrv +
Evan Wright
Guillaume Gay
Hamed Saljooghinejad +
Iblis Lin +
Jake VanderPlas
Jan Schulz
Jean-Mathieu Deschenes +
Jeff Reback
Jimmy Callin +
Joris Van den Bossche
K.-Michael Aye
Ka Wo Chen
Loïc Séguin-C +
Luo Yicheng +
Magnus Jöud +
Manuel Leonhardt +
Matthew Gilbert
Maximilian Roos
Michael +
Nicholas Stahl +
Nicolas Bonnotte +
Pastafarianist +
Petra Chong +
Phil Schaf +
Philipp A +
Rob deCarvalho +
Roman Khomenko +
Rémy Léone +
Sebastian Bank +
Sinhrks
Stephan Hoyer
Thierry Moisan
Tom Augspurger
Tux1 +
Varun +
Wieland Hoffmann +
Winterflower
Yoav Ram +
Younggun Kim
Zeke +
ajcr
azuranski +
behzad nouri
cel4
emilydolson +
hironow +
lexual
llllllllll +
rockg
silentquasar +
sinhrks
taeold +