版本 0.9.1 (2012 年 11 月 14 日)#
這是 0.9.0 的一個錯誤修復版本,其中包含一些新功能和改進,以及大量的錯誤修復。新功能包括 DataFrame 和 Series 的按列排序順序、rank 方法改進的 NA 處理、DataFrame 的掩碼函式以及 DataFrame 的日內時間序列過濾。
新功能#
Series.sort、DataFrame.sort和DataFrame.sort_index現在可以按每列的方式指定,以支援多重排序順序(GH 928)In [2]: df = pd.DataFrame(np.random.randint(0, 2, (6, 3)), ...: columns=['A', 'B', 'C']) In [3]: df.sort(['A', 'B'], ascending=[1, 0]) Out[3]: A B C 3 0 1 1 4 0 1 1 2 0 0 1 0 1 0 0 1 1 0 0 5 1 0 0
DataFrame.rank現在支援na_option引數的附加引數值,以便將缺失值分配給最大或最小的排名(GH 1508、GH 2159)In [1]: df = pd.DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C']) In [2]: df.loc[2:4] = np.nan In [3]: df.rank() Out[3]: A B C 0 3.0 2.0 1.0 1 1.0 3.0 2.0 2 NaN NaN NaN 3 NaN NaN NaN 4 NaN NaN NaN 5 2.0 1.0 3.0 In [4]: df.rank(na_option='top') Out[4]: A B C 0 6.0 5.0 4.0 1 4.0 6.0 5.0 2 2.0 2.0 2.0 3 2.0 2.0 2.0 4 2.0 2.0 2.0 5 5.0 4.0 6.0 In [5]: df.rank(na_option='bottom') Out[5]: A B C 0 3.0 2.0 1.0 1 1.0 3.0 2.0 2 5.0 5.0 5.0 3 5.0 5.0 5.0 4 5.0 5.0 5.0 5 2.0 1.0 3.0DataFrame 具有新的
where和mask方法,可以根據給定的布林掩碼選擇值(GH 2109、GH 2151)DataFrame 目前支援透過與 DataFrame 長度相同的布林向量進行切片(在
[]內部)。返回的 DataFrame 具有與原始 DataFrame 相同的列數,但根據其索引進行切片。In [6]: df = pd.DataFrame(np.random.randn(5, 3), columns=['A', 'B', 'C']) In [7]: df Out[7]: A B C 0 0.276232 -1.087401 -0.673690 1 0.113648 -1.478427 0.524988 2 0.404705 0.577046 -1.715002 3 -1.039268 -0.370647 -1.157892 4 -1.344312 0.844885 1.075770 In [8]: df[df['A'] > 0] Out[8]: A B C 0 0.276232 -1.087401 -0.673690 1 0.113648 -1.478427 0.524988 2 0.404705 0.577046 -1.715002如果使用基於 DataFrame 的布林條件(大小與原始 DataFrame 相同)對 DataFrame 進行切片,則返回一個與原始 DataFrame 大小(索引和列)相同的 DataFrame,其中不滿足布林條件的值將替換為
NaN。這可以透過新的DataFrame.where方法實現。此外,where還可以接受一個可選的other引數進行替換。In [9]: df[df > 0] Out[9]: A B C 0 0.276232 NaN NaN 1 0.113648 NaN 0.524988 2 0.404705 0.577046 NaN 3 NaN NaN NaN 4 NaN 0.844885 1.075770 In [10]: df.where(df > 0) Out[10]: A B C 0 0.276232 NaN NaN 1 0.113648 NaN 0.524988 2 0.404705 0.577046 NaN 3 NaN NaN NaN 4 NaN 0.844885 1.075770 In [11]: df.where(df > 0, -df) Out[11]: A B C 0 0.276232 1.087401 0.673690 1 0.113648 1.478427 0.524988 2 0.404705 0.577046 1.715002 3 1.039268 0.370647 1.157892 4 1.344312 0.844885 1.075770此外,
where現在可以對輸入的布林條件(ndarray 或 DataFrame)進行對齊,從而可以實現部分選擇和設定。這類似於透過.ix進行部分設定(但作用於內容而不是軸標籤)。In [12]: df2 = df.copy() In [13]: df2[df2[1:4] > 0] = 3 In [14]: df2 Out[14]: A B C 0 0.276232 -1.087401 -0.673690 1 3.000000 -1.478427 3.000000 2 3.000000 3.000000 -1.715002 3 -1.039268 -0.370647 -1.157892 4 -1.344312 0.844885 1.075770
DataFrame.mask是where的反布林運算。In [15]: df.mask(df <= 0) Out[15]: A B C 0 0.276232 NaN NaN 1 0.113648 NaN 0.524988 2 0.404705 0.577046 NaN 3 NaN NaN NaN 4 NaN 0.844885 1.075770允許透過 Excel 列名引用 Excel 列(GH 1936)
In [1]: xl = pd.ExcelFile('data/test.xls') In [2]: xl.parse('Sheet1', index_col=0, parse_dates=True, parse_cols='A:D')透過
series.plot(x_compat=True)或pandas.plot_params['x_compat'] = True添加了停用 pandas 風格的刻度定位器和格式化器的選項(GH 2205)現有的 TimeSeries 方法
at_time和between_time已新增到 DataFrame 中(GH 2149)DataFrame.dot 現在可以接受 ndarrays(GH 2042)
DataFrame.drop 現在支援非唯一索引(GH 2101)
Panel.shift 現在支援負週期(GH 2164)
DataFrame 現在支援一元 ~ 運算子(GH 2110)
API 更改#
使用 PeriodIndex 進行上取樣資料將導致一個更高頻率的時間序列,該時間序列跨越原始時間視窗
In [1]: prng = pd.period_range('2012Q1', periods=2, freq='Q') In [2]: s = pd.Series(np.random.randn(len(prng)), prng) In [4]: s.resample('M') Out[4]: 2012-01 -1.471992 2012-02 NaN 2012-03 NaN 2012-04 -0.493593 2012-05 NaN 2012-06 NaN Freq: M, dtype: float64Period.end_time 現在返回時間間隔內的最後一個納秒(GH 2124、GH 2125、GH 1764)
In [16]: p = pd.Period('2012') In [17]: p.end_time Out[17]: Timestamp('2012-12-31 23:59:59.999999')對於指定了自定義轉換器的列,檔案解析器不再強制轉換為 float 或 bool(GH 2184)
In [18]: import io In [19]: data = ('A,B,C\n' ....: '00001,001,5\n' ....: '00002,002,6') ....: In [20]: pd.read_csv(io.StringIO(data), converters={'A': lambda x: x.strip()}) Out[20]: A B C 0 00001 1 5 1 00002 2 6
請參閱 完整的釋出說明 或 GitHub 上的問題跟蹤器以獲取完整列表。
貢獻者#
共有 11 人為本次釋出貢獻了補丁。名字旁邊有“+”的人是第一次貢獻補丁。
Brenda Moon +
Chang She
Jeff Reback +
Justin C Johnson +
K.-Michael Aye
Martin Blais
Tobias Brandt +
Wes McKinney
Wouter Overmeire
timmie
y-p