版本 0.20.1(2017 年 5 月 5 日)#

這是從 0.19.2 版本進行的一次重大發布,其中包括一系列 API 更改、棄用、新功能、增強功能和效能改進,以及大量的錯誤修復。我們建議所有使用者升級到此版本。

亮點包括

  • 新增了適用於 Series/DataFrame 的 .agg() API,類似於 groupby-rolling-resample API,請參見 此處

  • feather-format 整合,包括新的頂級 pd.read_feather()DataFrame.to_feather() 方法,請參見 此處

  • .ix 索引器已被棄用,請參見 此處

  • Panel 已被棄用,請參見 此處

  • 添加了 IntervalIndexInterval 標量型別,請參見 此處

  • .groupby() 中按索引級別分組時,改進了使用者 API,請參見 此處

  • 改進了對 UInt64 資料型別的支援,請參見 此處

  • JSON 序列化的一種新方向 orient='table',它使用 Table Schema 規範,併為 Jupyter Notebook 中的互動式表示提供了可能性,請參見 此處

  • 實驗性支援將樣式化的 DataFrames (DataFrame.style) 匯出到 Excel,請參見 此處

  • 視窗二元 corr/cov 操作現在返回一個 MultiIndexed DataFrame 而不是 Panel,因為 Panel 現已棄用,請參見 此處

  • 對 S3 的支援現在使用 s3fs,請參見 此處

  • Google BigQuery 支援現在使用 pandas-gbq 庫,請參見 此處

警告

pandas 更改了程式碼庫的內部結構和佈局。這可能會影響未從頂級 pandas.* 名稱空間匯入的內容,請參見 此處 的更改。

更新前請檢查 API 更改棄用項

注意

這是 0.20.0 和 0.20.1 的合併版本。0.20.1 版本包含一項額外的向後相容性更改,以支援使用 pandas 的 utils 例程的下游專案。(GH 16250

新功能#

DataFrame/Series 的 agg 方法 API#

Series 和 DataFrame 已增強以支援聚合 API。這是來自 groupby、視窗操作和重取樣的熟悉 API。透過使用 agg()transform(),可以簡潔地進行聚合操作。完整文件在此處(GH 1623)。

這是一個示例

In [1]: df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'],
   ...:                   index=pd.date_range('1/1/2000', periods=10))
   ...: 

In [2]: df.iloc[3:7] = np.nan

In [3]: df
Out[3]: 
                   A         B         C
2000-01-01  0.469112 -0.282863 -1.509059
2000-01-02 -1.135632  1.212112 -0.173215
2000-01-03  0.119209 -1.044236 -0.861849
2000-01-04       NaN       NaN       NaN
2000-01-05       NaN       NaN       NaN
2000-01-06       NaN       NaN       NaN
2000-01-07       NaN       NaN       NaN
2000-01-08  0.113648 -1.478427  0.524988
2000-01-09  0.404705  0.577046 -1.715002
2000-01-10 -1.039268 -0.370647 -1.157892

可以使用字串函式名稱、可呼叫物件、列表或它們的字典進行操作。

使用單個函式等同於 .apply

In [4]: df.agg('sum')
Out[4]: 
A   -1.068226
B   -1.387015
C   -4.892029
dtype: float64

使用函式列表進行多次聚合。

In [5]: df.agg(['sum', 'min'])
Out[5]: 
            A         B         C
sum -1.068226 -1.387015 -4.892029
min -1.135632 -1.478427 -1.715002

使用字典可以對每列應用特定的聚合。您將獲得所有聚合器的矩陣狀輸出。輸出有一列代表一個唯一的函式。應用於特定列的函式將是 NaN

In [6]: df.agg({'A': ['sum', 'min'], 'B': ['min', 'max']})
Out[6]: 
            A         B
sum -1.068226       NaN
min -1.135632 -1.478427
max       NaN  1.212112

API 還支援用於廣播結果的 .transform() 函式。

In [7]: df.transform(['abs', lambda x: x - x.min()])
Out[7]: 
                   A                   B                   C          
                 abs  <lambda>       abs  <lambda>       abs  <lambda>
2000-01-01  0.469112  1.604745  0.282863  1.195563  1.509059  0.205944
2000-01-02  1.135632  0.000000  1.212112  2.690539  0.173215  1.541787
2000-01-03  0.119209  1.254841  1.044236  0.434191  0.861849  0.853153
2000-01-04       NaN       NaN       NaN       NaN       NaN       NaN
2000-01-05       NaN       NaN       NaN       NaN       NaN       NaN
2000-01-06       NaN       NaN       NaN       NaN       NaN       NaN
2000-01-07       NaN       NaN       NaN       NaN       NaN       NaN
2000-01-08  0.113648  1.249281  1.478427  0.000000  0.524988  2.239990
2000-01-09  0.404705  1.540338  0.577046  2.055473  1.715002  0.000000
2000-01-10  1.039268  0.096364  0.370647  1.107780  1.157892  0.557110

當遇到無法聚合的混合 dtype 時,.agg() 只會執行有效的聚合。這類似於 groupby .agg() 的工作方式。(GH 15015

In [8]: df = pd.DataFrame({'A': [1, 2, 3],
   ...:                    'B': [1., 2., 3.],
   ...:                    'C': ['foo', 'bar', 'baz'],
   ...:                    'D': pd.date_range('20130101', periods=3)})
   ...: 

In [9]: df.dtypes
Out[9]: 
A             int64
B           float64
C               str
D    datetime64[us]
dtype: object
In [10]: df.agg(['min', 'sum'])
Out[10]:
     A    B          C          D
min  1  1.0        bar 2013-01-01
sum  6  6.0  foobarbaz        NaT

資料 IO 的 dtype 關鍵字引數#

用於解析固定寬度文字檔案的 'python' 引擎的 read_csv(),以及 read_fwf() 函式,以及用於解析 Excel 檔案的 read_excel(),現在都接受 dtype 關鍵字引數來指定特定列的型別(GH 14295)。有關更多資訊,請參閱 IO 文件

In [10]: data = "a  b\n1  2\n3  4"

In [11]: pd.read_fwf(StringIO(data)).dtypes
Out[11]: 
a    int64
b    int64
dtype: object

In [12]: pd.read_fwf(StringIO(data), dtype={'a': 'float64', 'b': 'object'}).dtypes
Out[12]: 
a    float64
b     object
dtype: object

.to_datetime() 方法已獲得 origin 引數#

to_datetime() 已獲得一個新的引數 origin,用於在解析具有特定 unit 指定的數值時,定義一個計算最終時間戳的參考日期。(GH 11276, GH 11745

例如,以 1960-01-01 為起始日期

In [13]: pd.to_datetime([1, 2, 3], unit='D', origin=pd.Timestamp('1960-01-01'))
Out[13]: DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], dtype='datetime64[s]', freq=None)

預設值為 origin='unix',它預設為 1970-01-01 00:00:00,這通常稱為“unix 紀元”或 POSIX 時間。這是之前的預設值,因此這是一項向後相容的更改。

In [14]: pd.to_datetime([1, 2, 3], unit='D')
Out[14]: DatetimeIndex(['1970-01-02', '1970-01-03', '1970-01-04'], dtype='datetime64[s]', freq=None)

GroupBy 增強功能#

作為 by 引數傳遞給 DataFrame.groupby() 的字串現在可以引用列名或索引級別名稱。以前只能引用列名。這允許輕鬆地同時按列和索引級別進行分組。(GH 5677

In [15]: arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
   ....:           ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
   ....: 

In [16]: index = pd.MultiIndex.from_arrays(arrays, names=['first', 'second'])

In [17]: df = pd.DataFrame({'A': [1, 1, 1, 1, 2, 2, 3, 3],
   ....:                    'B': np.arange(8)},
   ....:                   index=index)
   ....: 

In [18]: df
Out[18]: 
              A  B
first second      
bar   one     1  0
      two     1  1
baz   one     1  2
      two     1  3
foo   one     2  4
      two     2  5
qux   one     3  6
      two     3  7

In [19]: df.groupby(['second', 'A']).sum()
Out[19]: 
          B
second A   
one    1  2
       2  4
       3  6
two    1  4
       2  5
       3  7

read_csv 中對壓縮 URL 的更好支援#

壓縮程式碼已重構(GH 12688)。因此,在 read_csv()read_table() 中從 URL 讀取資料框現在支援額外的壓縮方法:xzbz2zipGH 14570)。之前只支援 gzip 壓縮。預設情況下,現在使用副檔名推斷 URL 和路徑的壓縮。此外,python 2 C 引擎中的 bz2 壓縮支援得到了改進(GH 14874)。

In [20]: url = ('https://github.com/{repo}/raw/{branch}/{path}'
   ....:        .format(repo='pandas-dev/pandas',
   ....:                branch='main',
   ....:                path='pandas/tests/io/parser/data/salaries.csv.bz2'))
   ....: 

# default, infer compression
In [21]: df = pd.read_csv(url, sep='\t', compression='infer')

# explicitly specify compression
In [22]: df = pd.read_csv(url, sep='\t', compression='bz2')

In [23]: df.head(2)
Out[23]: 
       S  X  E  M
0  13876  1  1  1
1  11608  1  3  0

Pickle 檔案 IO 現在支援壓縮#

read_pickle()DataFrame.to_pickle()Series.to_pickle() 現在可以讀寫壓縮的 pickle 檔案。壓縮方法可以是顯式引數,也可以從副檔名推斷。請在此處參閱 文件

In [24]: df = pd.DataFrame({'A': np.random.randn(1000),
   ....:                    'B': 'foo',
   ....:                    'C': pd.date_range('20130101', periods=1000, freq='s')})
   ....: 

使用顯式的壓縮型別

In [25]: df.to_pickle("data.pkl.compress", compression="gzip")

In [26]: rt = pd.read_pickle("data.pkl.compress", compression="gzip")

In [27]: rt.head()
Out[27]: 
          A    B                   C
0 -1.344312  foo 2013-01-01 00:00:00
1  0.844885  foo 2013-01-01 00:00:01
2  1.075770  foo 2013-01-01 00:00:02
3 -0.109050  foo 2013-01-01 00:00:03
4  1.643563  foo 2013-01-01 00:00:04

預設是從副檔名推斷壓縮型別(compression='infer'

In [28]: df.to_pickle("data.pkl.gz")

In [29]: rt = pd.read_pickle("data.pkl.gz")

In [30]: rt.head()
Out[30]: 
          A    B                   C
0 -1.344312  foo 2013-01-01 00:00:00
1  0.844885  foo 2013-01-01 00:00:01
2  1.075770  foo 2013-01-01 00:00:02
3 -0.109050  foo 2013-01-01 00:00:03
4  1.643563  foo 2013-01-01 00:00:04

In [31]: df["A"].to_pickle("s1.pkl.bz2")

In [32]: rt = pd.read_pickle("s1.pkl.bz2")

In [33]: rt.head()
Out[33]: 
0   -1.344312
1    0.844885
2    1.075770
3   -0.109050
4    1.643563
Name: A, dtype: float64

UInt64 支援得到改進#

pandas 顯著改進了對涉及無符號或純非負整數的操作的支援。以前,處理這些整數會導致不正確的舍入或資料型別轉換,從而導致錯誤的結果。值得注意的是,建立了一個新的數值索引 UInt64IndexGH 14937)。

In [1]: idx = pd.UInt64Index([1, 2, 3])
In [2]: df = pd.DataFrame({'A': ['a', 'b', 'c']}, index=idx)
In [3]: df.index
Out[3]: UInt64Index([1, 2, 3], dtype='uint64')
  • 將類陣列物件的元素轉換為無符號 64 位整數的 bug(GH 4471, GH 14982

  • Series.unique() 中導致無符號 64 位整數溢位的 bug(GH 14721

  • DataFrame 構建中將無符號 64 位整數元素轉換為物件的 bug(GH 14881

  • pd.read_csv() 中將無符號 64 位整數元素錯誤地轉換為錯誤資料型別的 bug(GH 14983

  • pd.unique() 中導致無符號 64 位整數溢位的 bug(GH 14915

  • pd.value_counts() 中導致輸出中的無符號 64 位整數被錯誤截斷的 bug(GH 14934

基於分類資料的 GroupBy#

在之前的版本中,當在具有某些未出現在資料中的類別的分類 Series 上分組時,.groupby(..., sort=False) 會因 ValueError 而失敗。(GH 13179

In [34]: chromosomes = np.r_[np.arange(1, 23).astype(str), ['X', 'Y']]

In [35]: df = pd.DataFrame({
   ....:     'A': np.random.randint(100),
   ....:     'B': np.random.randint(100),
   ....:     'C': np.random.randint(100),
   ....:     'chromosomes': pd.Categorical(np.random.choice(chromosomes, 100),
   ....:                                   categories=chromosomes,
   ....:                                   ordered=True)})
   ....: 

In [36]: df
Out[36]: 
     A   B   C chromosomes
0   87  22  81           4
1   87  22  81          13
2   87  22  81          22
3   87  22  81           2
4   87  22  81           6
..  ..  ..  ..         ...
95  87  22  81           8
96  87  22  81          11
97  87  22  81           X
98  87  22  81           1
99  87  22  81          19

[100 rows x 4 columns]

先前行為:

In [3]: df[df.chromosomes != '1'].groupby('chromosomes', observed=False, sort=False).sum()
---------------------------------------------------------------------------
ValueError: items in new_categories are not the same as in old categories

新行為:

In [37]: df[df.chromosomes != '1'].groupby('chromosomes', observed=False, sort=False).sum()
Out[37]: 
               A   B    C
chromosomes              
4            348  88  324
13           261  66  243
22           348  88  324
2            348  88  324
6            174  44  162
...          ...  ..  ...
3            348  88  324
11           348  88  324
19           174  44  162
1              0   0    0
21             0   0    0

[24 rows x 3 columns]

表模式輸出#

用於 DataFrame.to_json() 的新方向 'table' 將生成與 Table Schema 相容的資料字串表示。

In [38]: df = pd.DataFrame(
   ....: {'A': [1, 2, 3],
   ....:  'B': ['a', 'b', 'c'],
   ....:  'C': pd.date_range('2016-01-01', freq='d', periods=3)},
   ....: index=pd.Index(range(3), name='idx'))
In [39]: df
Out[39]:
     A  B          C
idx
0    1  a 2016-01-01
1    2  b 2016-01-02
2    3  c 2016-01-03

[3 rows x 3 columns]

In [40]: df.to_json(orient='table')
Out[40]:
'{"schema":{"fields":[{"name":"idx","type":"integer"},{"name":"A","type":"integer"},{"name":"B","type":"string"},{"name":"C","type":"datetime"}],"primaryKey":["idx"],"pandas_version":"1.4.0"},"data":[{"idx":0,"A":1,"B":"a","C":"2016-01-01T00:00:00.000"},{"idx":1,"A":2,"B":"b","C":"2016-01-02T00:00:00.000"},{"idx":2,"A":3,"B":"c","C":"2016-01-03T00:00:00.000"}]}'

有關更多資訊,請參閱 IO:Table Schema

此外,對於 DataFrameSeries 的 repr 現在可以釋出 Series 或 DataFrame 的此 JSON Table Schema 表示,如果您使用的是 IPython(或其他使用 Jupyter 訊息協議的前端,如 nteract)。這為 Jupyter Notebook 和 nteract 等前端提供了更大的靈活性來顯示 pandas 物件,因為它們擁有更多關於資料的資訊。您必須透過將 display.html.table_schema 選項設定為 True 來啟用此功能。

SciPy 稀疏矩陣與 SparseDataFrame 之間的轉換#

pandas 現在支援直接從 scipy.sparse.spmatrix 例項建立稀疏資料框。有關更多資訊,請參閱 文件。(GH 4343

所有稀疏格式都得到支援,但非 COOrdinate 格式的矩陣將被轉換,並在需要時複製資料。

from scipy.sparse import csr_matrix
arr = np.random.random(size=(1000, 5))
arr[arr < .9] = 0
sp_arr = csr_matrix(arr)
sp_arr
sdf = pd.SparseDataFrame(sp_arr)
sdf

要將 SparseDataFrame 轉換回 COO 格式的 SciPy 稀疏矩陣,您可以使用

sdf.to_coo()

樣式化 DataFrame 的 Excel 輸出#

已新增實驗性支援,使用 openpyxl 引擎將 DataFrame.style 格式匯出到 Excel。(GH 15530

例如,執行以下命令後,styled.xlsx 呈現如下:

In [38]: np.random.seed(24)

In [39]: df = pd.DataFrame({'A': np.linspace(1, 10, 10)})

In [40]: df = pd.concat([df, pd.DataFrame(np.random.RandomState(24).randn(10, 4),
   ....:                                  columns=list('BCDE'))],
   ....:                axis=1)
   ....: 

In [41]: df.iloc[0, 2] = np.nan

In [42]: df
Out[42]: 
      A         B         C         D         E
0   1.0  1.329212       NaN -0.316280 -0.990810
1   2.0 -1.070816 -1.438713  0.564417  0.295722
2   3.0 -1.626404  0.219565  0.678805  1.889273
3   4.0  0.961538  0.104011 -0.481165  0.850229
4   5.0  1.453425  1.057737  0.165562  0.515018
5   6.0 -1.336936  0.562861  1.392855 -0.063328
6   7.0  0.121668  1.207603 -0.002040  1.627796
7   8.0  0.354493  1.037528 -0.385684  0.519818
8   9.0  1.686583 -1.325963  1.428984 -2.089354
9  10.0 -0.129820  0.631523 -0.586538  0.290720

In [43]: styled = (df.style
   ....:           .map(lambda val: 'color:red;' if val < 0 else 'color:black;')
   ....:           .highlight_max())
   ....: 

In [44]: styled.to_excel('styled.xlsx', engine='openpyxl')
../_images/style-excel.png

有關更多詳細資訊,請參閱 Style 文件

IntervalIndex#

pandas 增加了 IntervalIndex,它有自己的 dtype interval,以及 Interval 標量型別。這些型別為區間表示提供了第一類支援,特別是在 cut()qcut() 中作為類別返回值。 IntervalIndex 允許一些獨特的索引,請參閱 文件。(GH 7640, GH 8625

警告

IntervalIndex 的這些索引行為是暫時的,可能會在 pandas 的未來版本中發生更改。歡迎對使用提出反饋。

先前行為

返回的類別是字串,代表區間。

In [1]: c = pd.cut(range(4), bins=2)

In [2]: c
Out[2]:
[(-0.003, 1.5], (-0.003, 1.5], (1.5, 3], (1.5, 3]]
Categories (2, object): [(-0.003, 1.5] < (1.5, 3]]

In [3]: c.categories
Out[3]: Index(['(-0.003, 1.5]', '(1.5, 3]'], dtype='object')

新行為

In [45]: c = pd.cut(range(4), bins=2)

In [46]: c
Out[46]: 
[(-0.003, 1.5], (-0.003, 1.5], (1.5, 3.0], (1.5, 3.0]]
Categories (2, interval[float64, right]): [(-0.003, 1.5] < (1.5, 3.0]]

In [47]: c.categories
Out[47]: IntervalIndex([(-0.003, 1.5], (1.5, 3.0]], dtype='interval[float64, right]')

此外,這使得可以使用相同的區間來對 *其他* 資料進行分箱,其中 NaN 表示缺失值,類似於其他 dtype。

In [48]: pd.cut([0, 3, 5, 1], bins=c.categories)
Out[48]: 
[(-0.003, 1.5], (1.5, 3.0], NaN, (-0.003, 1.5]]
Categories (2, interval[float64, right]): [(-0.003, 1.5] < (1.5, 3.0]]

IntervalIndex 也可以在 SeriesDataFrame 中用作索引。

In [49]: df = pd.DataFrame({'A': range(4),
   ....:                    'B': pd.cut([0, 3, 1, 1], bins=c.categories)
   ....:                    }).set_index('B')
   ....: 

In [50]: df
Out[50]: 
               A
B               
(-0.003, 1.5]  0
(1.5, 3.0]     1
(-0.003, 1.5]  2
(-0.003, 1.5]  3

透過特定區間選擇

In [51]: df.loc[pd.Interval(1.5, 3.0)]
Out[51]: 
A    1
Name: (1.5, 3.0], dtype: int64

透過包含在區間內的標量值進行選擇。

In [52]: df.loc[0]
Out[52]: 
               A
B               
(-0.003, 1.5]  0
(-0.003, 1.5]  2
(-0.003, 1.5]  3

其他增強功能#

  • DataFrame.rolling() 現在接受引數 closed='right'|'left'|'both'|'neither' 來選擇滾動視窗的端點閉合性。請參閱 文件。(GH 13965

  • feather-format 整合,包括新的頂級 pd.read_feather()DataFrame.to_feather() 方法,請參見 此處

  • Series.str.replace() 現在接受一個可呼叫物件作為替換項,該物件會被傳遞給 re.sub。(GH 15055

  • Series.str.replace() 現在接受一個已編譯的正則表示式作為模式。(GH 15446

  • Series.sort_index 接受引數 kindna_position。(GH 13589, GH 14444

  • DataFrameDataFrame.groupby() 已獲得 nunique() 方法,用於計算軸上的不同值。(GH 14336, GH 15197)。

  • DataFrame 已獲得 melt() 方法,等同於 pd.melt(),用於將寬格式非透視到長格式(GH 12640)。

  • pd.read_excel() 現在在使用 sheetname=None 時保留工作表順序(GH 9930)。

  • 現在支援帶有小數點的多個偏移量別名(例如,0.5min 被解析為 30s)(GH 8419)。

  • .isnull().notnull() 已新增到 Index 物件中,以使其與 Series API 保持一致(GH 15300)。

  • UnsortedIndexErrorKeyError 的子類)在索引/切片到未排序的 MultiIndex 時引發(GH 11897)。這允許區分由於未排序或鍵不正確而導致的錯誤。請參見 此處

  • MultiIndex 已獲得 .to_frame() 方法,用於轉換為 DataFrameGH 12397)。

  • pd.cutpd.qcut 現在支援 datetime64 和 timedelta64 dtypes(GH 14714, GH 14798)。

  • pd.qcut 已獲得 duplicates='raise'|'drop' 選項,用於控制是否在重複邊緣處引發錯誤(GH 7751)。

  • Series 提供 to_excel 方法以輸出 Excel 檔案(GH 8825)。

  • pd.read_csv() 中的 usecols 引數現在接受可呼叫函式作為值(GH 14154)。

  • pd.read_csv() 中的 skiprows 引數現在接受可呼叫函式作為值(GH 10882)。

  • pd.read_csv() 中的 nrowschunksize 引數如果兩者都傳遞則得到支援(GH 6774, GH 15755)。

  • DataFrame.plot 現在會在每個子圖上方列印標題,如果 suplots=Truetitle 是字串列表(GH 14753)。

  • DataFrame.plot 可以將 matplotlib 2.0 預設顏色迴圈作為單個字串傳遞給 color 引數,請參見 此處。(GH 15516

  • Series.interpolate() 現在支援將 timedelta 作為索引型別,並使用 method='time'GH 6424)。

  • DataFrame/Series.rename 中添加了 level 關鍵字,用於重新命名 MultiIndex 指定級別中的標籤(GH 4160)。

  • DataFrame.reset_index() 現在會將一個元組 index.name 解釋為跨越 columns 級別的鍵,如果這是一個 MultiIndexGH 16164)。

  • 添加了 Timedelta.isoformat 方法,用於將 Timedeltas 格式化為 ISO 8601 持續時間。請參閱 Timedelta 文件GH 15136)。

  • .select_dtypes() 現在允許字串 datetimetz 來泛化選擇帶有時區的日期時間(GH 14910)。

  • .to_latex() 方法現在將接受 multicolumnmultirow 引數,以使用相應的 LaTeX 增強功能。

  • pd.merge_asof() 增加了 direction='backward'|'forward'|'nearest' 選項(GH 14887)。

  • Series/DataFrame.asfreq() 已獲得 fill_value 引數,用於填充缺失值(GH 3715)。

  • Series/DataFrame.resample.asfreq 已獲得 fill_value 引數,用於在重取樣過程中填充缺失值(GH 3715)。

  • pandas.util.hash_pandas_object() 已獲得對 MultiIndex 進行雜湊處理的能力(GH 15224)。

  • Series/DataFrame.squeeze() 已獲得 axis 引數。(GH 15339

  • DataFrame.to_excel() 有一個新的 freeze_panes 引數,用於在匯出到 Excel 時開啟凍結窗格(GH 15160)。

  • pd.read_html() 將解析多個表頭行,建立 MultiIndex 表頭。( GH 13434)。

  • HTML 表格輸出會跳過 colspanrowspan 屬性,如果其值等於 1。( GH 15403)

  • pandas.io.formats.style.Styler 模板現在有方便擴充套件的塊,請參閱 示例 notebook (GH 15649)

  • Styler.render() 現在接受 **kwargs,以允許在模板中使用使用者定義的變數 (GH 15649)

  • 與 Jupyter notebook 5.0 的相容性;MultiIndex 列標籤左對齊,MultiIndex 行標籤頂端對齊 (GH 15379)

  • TimedeltaIndex 現在擁有一個自定義的日期刻度格式器,專門為納秒級精度設計 (GH 8711)

  • pd.api.types.union_categoricals 增加了 ignore_ordered 引數,以允許忽略聯合分類資料的有序屬性 (GH 13410)。有關更多資訊,請參閱 分類聯合文件

  • DataFrame.to_latex()DataFrame.to_string() 現在允許可選的表頭別名。( GH 15536)

  • 重新啟用 pd.read_excel()parse_dates 關鍵字引數,用於將字串列解析為日期 (GH 14326)

  • Index 的子類添加了 .empty 屬性。( GH 15270)

  • TimedeltaTimedeltaIndex 啟用了整除運算 (GH 15828)

  • pandas.io.json.json_normalize() 增加了 errors='ignore'|'raise' 選項;預設值為 errors='raise',這向後相容。( GH 14583)

  • pandas.io.json.json_normalize() 與一個空的 list 將返回一個空的 DataFrame (GH 15534)

  • pandas.io.json.json_normalize() 增加了一個 sep 選項,該選項接受 str 來分隔連線的欄位;預設值為 ".",這是向後相容的。( GH 14883)

  • 已新增 MultiIndex.remove_unused_levels() 以方便 移除未使用的級別。( GH 15694)

  • pd.read_csv() 現在將在發生任何解析錯誤時引發 ParserError 錯誤 (GH 15913, GH 15925)

  • pd.read_csv() 現在支援 Python 解析器的 error_bad_lineswarn_bad_lines 引數 (GH 15925)

  • 現在可以使用 display.show_dimensions 選項來指定是否在 Series 的 repr 中顯示其長度 (GH 7117)。

  • parallel_coordinates() 增加了一個 sort_labels 關鍵字引數,用於對類標籤及其分配的顏色進行排序 (GH 15908)

  • 添加了選項以允許開啟/關閉使用 bottlenecknumexpr,請參閱 此處 (GH 16157)

  • DataFrame.style.bar() 現在接受另外兩個選項來進一步自定義條形圖。條形對齊使用 align='left'|'mid'|'zero' 設定,預設為“left”,這是向後相容的;現在您可以傳遞一個 color=[color_negative, color_positive] 列表。( GH 14757)

向後不相容的 API 更改#

與 pandas < 0.13.0 建立的 HDF5 格式可能存在不相容性 #

pd.TimeSeries 在 0.17.0 中被正式棄用,儘管自 0.13.0 起它已經是別名。它已被 pd.Series 取代。( GH 15098)。

可能導致使用 pandas < 0.13.0 的先前版本建立的 HDF5 檔案在 pd.TimeSeries 被使用時變得不可讀。如果您遇到這種情況,可以使用 pandas 的一個較早版本來讀取您的 HDF5 檔案,然後按照以下步驟將其寫出。

In [2]: s = pd.TimeSeries([1, 2, 3], index=pd.date_range('20130101', periods=3))

In [3]: s
Out[3]:
2013-01-01    1
2013-01-02    2
2013-01-03    3
Freq: D, dtype: int64

In [4]: type(s)
Out[4]: pandas.core.series.TimeSeries

In [5]: s = pd.Series(s)

In [6]: s
Out[6]:
2013-01-01    1
2013-01-02    2
2013-01-03    3
Freq: D, dtype: int64

In [7]: type(s)
Out[7]: pandas.core.series.Series

Index 型別上的 Map 現在返回其他 Index 型別 #

Index 上使用 map 現在返回一個 Index,而不是 numpy 陣列 (GH 12766)

In [53]: idx = pd.Index([1, 2])

In [54]: idx
Out[54]: Index([1, 2], dtype='int64')

In [55]: mi = pd.MultiIndex.from_tuples([(1, 2), (2, 4)])

In [56]: mi
Out[56]: 
MultiIndex([(1, 2),
            (2, 4)],
           )

先前行為

In [5]: idx.map(lambda x: x * 2)
Out[5]: array([2, 4])

In [6]: idx.map(lambda x: (x, x * 2))
Out[6]: array([(1, 2), (2, 4)], dtype=object)

In [7]: mi.map(lambda x: x)
Out[7]: array([(1, 2), (2, 4)], dtype=object)

In [8]: mi.map(lambda x: x[0])
Out[8]: array([1, 2])

新行為

In [57]: idx.map(lambda x: x * 2)
Out[57]: Index([2, 4], dtype='int64')

In [58]: idx.map(lambda x: (x, x * 2))
Out[58]: 
MultiIndex([(1, 2),
            (2, 4)],
           )

In [59]: mi.map(lambda x: x)
Out[59]: 
MultiIndex([(1, 2),
            (2, 4)],
           )

In [60]: mi.map(lambda x: x[0])
Out[60]: Index([1, 2], dtype='int64')

具有 datetime64 值的 Series 上的 map 可能返回 int64 dtypes 而不是 int32

In [64]: s = pd.Series(pd.date_range('2011-01-02T00:00', '2011-01-02T02:00', freq='H')
   ....:               .tz_localize('Asia/Tokyo'))
   ....:

In [65]: s
Out[65]:
0   2011-01-02 00:00:00+09:00
1   2011-01-02 01:00:00+09:00
2   2011-01-02 02:00:00+09:00
Length: 3, dtype: datetime64[ns, Asia/Tokyo]

先前行為

In [9]: s.map(lambda x: x.hour)
Out[9]:
0    0
1    1
2    2
dtype: int32

新行為

In [66]: s.map(lambda x: x.hour)
Out[66]:
0    0
1    1
2    2
Length: 3, dtype: int64

訪問 Index 的 datetime 欄位現在返回 Index #

先前 DatetimeIndexPeriodIndexTimedeltaIndex 的日期時間相關屬性(概述請參閱 此處)會返回 numpy 陣列。現在它們將返回一個新的 Index 物件,但在布林欄位的情況下,結果仍將是布林 ndarray。( GH 15022)

先前行為

In [1]: idx = pd.date_range("2015-01-01", periods=5, freq='10H')

In [2]: idx.hour
Out[2]: array([ 0, 10, 20,  6, 16], dtype=int32)

新行為

In [67]: idx = pd.date_range("2015-01-01", periods=5, freq='10H')

In [68]: idx.hour
Out[68]: Index([0, 10, 20, 6, 16], dtype='int32')

這樣做的優點是可以對結果使用特定的 Index 方法。另一方面,這可能存在向後不相容性:例如,與 numpy 陣列相比,Index 物件是不可變的。要獲取原始 ndarray,您始終可以使用 np.asarray(idx.hour) 進行顯式轉換。

pd.unique 現在將與擴充套件型別保持一致 #

在先前版本中,對 Categorical 和帶時區的資料型別使用 Series.unique()pandas.unique() 會產生不同的返回型別。現在已使它們保持一致。( GH 15903)

  • 帶時區的 Datetime

    先前行為

    # Series
    In [5]: pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
       ...:            pd.Timestamp('20160101', tz='US/Eastern')]).unique()
    Out[5]: array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
    
    In [6]: pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
       ...:                      pd.Timestamp('20160101', tz='US/Eastern')]))
    Out[6]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
    
    # Index
    In [7]: pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
       ...:           pd.Timestamp('20160101', tz='US/Eastern')]).unique()
    Out[7]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None)
    
    In [8]: pd.unique([pd.Timestamp('20160101', tz='US/Eastern'),
       ...:            pd.Timestamp('20160101', tz='US/Eastern')])
    Out[8]: array(['2016-01-01T05:00:00.000000000'], dtype='datetime64[ns]')
    

    新行為

    # Series, returns an array of Timestamp tz-aware
    In [61]: pd.Series([pd.Timestamp(r'20160101', tz=r'US/Eastern'),
       ....:            pd.Timestamp(r'20160101', tz=r'US/Eastern')]).unique()
       ....: 
    Out[61]: 
    <DatetimeArray>
    ['2016-01-01 00:00:00-05:00']
    Length: 1, dtype: datetime64[us, US/Eastern]
    
    In [62]: pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'),
       ....:           pd.Timestamp('20160101', tz='US/Eastern')]))
       ....: 
    Out[62]: 
    <DatetimeArray>
    ['2016-01-01 00:00:00-05:00']
    Length: 1, dtype: datetime64[us, US/Eastern]
    
    # Index, returns a DatetimeIndex
    In [63]: pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
       ....:           pd.Timestamp('20160101', tz='US/Eastern')]).unique()
       ....: 
    Out[63]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[us, US/Eastern]', freq=None)
    
    In [64]: pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'),
       ....:                     pd.Timestamp('20160101', tz='US/Eastern')]))
       ....: 
    Out[64]: DatetimeIndex(['2016-01-01 00:00:00-05:00'], dtype='datetime64[us, US/Eastern]', freq=None)
    
  • 分類資料

    先前行為

    In [1]: pd.Series(list('baabc'), dtype='category').unique()
    Out[1]:
    [b, a, c]
    Categories (3, object): [b, a, c]
    
    In [2]: pd.unique(pd.Series(list('baabc'), dtype='category'))
    Out[2]: array(['b', 'a', 'c'], dtype=object)
    

    新行為

    # returns a Categorical
    In [65]: pd.Series(list('baabc'), dtype='category').unique()
    Out[65]: 
    ['b', 'a', 'c']
    Categories (3, str): ['a', 'b', 'c']
    
    In [66]: pd.unique(pd.Series(list('baabc'), dtype='category'))
    Out[66]: 
    ['b', 'a', 'c']
    Categories (3, str): ['a', 'b', 'c']
    

S3 檔案處理 #

pandas 現在使用 s3fs 處理 S3 連線。這不應破壞任何程式碼。但是,由於 s3fs 不是必需的依賴項,因此您需要單獨安裝它,就像 pandas 早期版本中的 boto 一樣。( GH 11915)。

部分字串索引更改 #

DatetimeIndex 部分字串索引 現在作為精確匹配工作,前提是字串解析度與索引解析度一致,包括兩者均為秒的情況 (GH 14826)。有關詳細資訊,請參閱 切片與精確匹配

In [67]: df = pd.DataFrame({'a': [1, 2, 3]}, pd.DatetimeIndex(['2011-12-31 23:59:59',
   ....:                                                       '2012-01-01 00:00:00',
   ....:                                                       '2012-01-01 00:00:01']))
   ....: 

先前行為

In [4]: df['2011-12-31 23:59:59']
Out[4]:
                       a
2011-12-31 23:59:59  1

In [5]: df['a']['2011-12-31 23:59:59']
Out[5]:
2011-12-31 23:59:59    1
Name: a, dtype: int64

新行為

In [4]: df['2011-12-31 23:59:59']
KeyError: '2011-12-31 23:59:59'

In [5]: df['a']['2011-12-31 23:59:59']
Out[5]: 1

不同浮點數 dtypes 的 Concat 將不再自動向上轉換 #

先前,具有不同 float dtypes 的多個物件的 concat 會自動將結果向上轉換為 float64 的 dtype。現在將使用可接受的最小 dtype (GH 13247)

In [68]: df1 = pd.DataFrame(np.array([1.0], dtype=np.float32, ndmin=2))

In [69]: df1.dtypes
Out[69]: 
0    float32
dtype: object

In [70]: df2 = pd.DataFrame(np.array([np.nan], dtype=np.float32, ndmin=2))

In [71]: df2.dtypes
Out[71]: 
0    float32
dtype: object

先前行為

In [7]: pd.concat([df1, df2]).dtypes
Out[7]:
0    float64
dtype: object

新行為

In [72]: pd.concat([df1, df2]).dtypes
Out[72]: 
0    float32
dtype: object

pandas Google BigQuery 支援已遷移 #

pandas 已將 Google BigQuery 支援拆分為一個單獨的包 pandas-gbq。您可以 conda install pandas-gbq -c conda-forgepip install pandas-gbq 來獲取它。read_gbq()DataFrame.to_gbq() 的功能在 pandas-gbq=0.1.4 的當前釋出版本中保持不變。文件現在託管在此處 (here) (GH 15347)

Index 的記憶體使用情況更準確 #

在先前版本中,對具有索引的 pandas 結構顯示 .memory_usage(),只會包含實際的索引值,而不包括促進快速索引的結構。這通常會與 IndexMultiIndex 有所不同,而對其他索引型別則影響較小。( GH 15237)

先前行為

In [8]: index = pd.Index(['foo', 'bar', 'baz'])

In [9]: index.memory_usage(deep=True)
Out[9]: 180

In [10]: index.get_loc('foo')
Out[10]: 0

In [11]: index.memory_usage(deep=True)
Out[11]: 180

新行為

In [8]: index = pd.Index(['foo', 'bar', 'baz'])

In [9]: index.memory_usage(deep=True)
Out[9]: 180

In [10]: index.get_loc('foo')
Out[10]: 0

In [11]: index.memory_usage(deep=True)
Out[11]: 260

DataFrame.sort_index 更改 #

在某些情況下,在具有 MultiIndex 的 DataFrame 上呼叫 .sort_index() 會返回同一個 DataFrame,但看起來沒有排序。這會發生在 lexsorted 但非單調的級別上。( GH 15622, GH 15687, GH 14015, GH 13431, GH 15797)

為了說明起見,這與先前版本不變

In [81]: df = pd.DataFrame(np.arange(6), columns=['value'],
   ....:                   index=pd.MultiIndex.from_product([list('BA'), range(3)]))
   ....:
In [82]: df

Out[82]:
     value
B 0      0
  1      1
  2      2
A 0      3
  1      4
  2      5

[6 rows x 1 columns]
In [87]: df.index.is_lexsorted()
Out[87]: False

In [88]: df.index.is_monotonic
Out[88]: False

排序按預期工作

In [73]: df.sort_index()
Out[73]: 
                     a
2011-12-31 23:59:59  1
2012-01-01 00:00:00  2
2012-01-01 00:00:01  3
In [90]: df.sort_index().index.is_lexsorted()
Out[90]: True

In [91]: df.sort_index().index.is_monotonic
Out[91]: True

然而,這個例子,它有一個非單調的第二個級別,並沒有按預期工作。

In [74]: df = pd.DataFrame({'value': [1, 2, 3, 4]},
   ....:                   index=pd.MultiIndex([['a', 'b'], ['bb', 'aa']],
   ....:                                       [[0, 0, 1, 1], [0, 1, 0, 1]]))
   ....: 

In [75]: df
Out[75]: 
      value
a bb      1
  aa      2
b bb      3
  aa      4

先前行為

In [11]: df.sort_index()
Out[11]:
      value
a bb      1
  aa      2
b bb      3
  aa      4

In [14]: df.sort_index().index.is_lexsorted()
Out[14]: True

In [15]: df.sort_index().index.is_monotonic
Out[15]: False

新行為

In [94]: df.sort_index()
Out[94]:
      value
a aa      2
  bb      1
b aa      4
  bb      3

[4 rows x 1 columns]

In [95]: df.sort_index().index.is_lexsorted()
Out[95]: True

In [96]: df.sort_index().index.is_monotonic
Out[96]: True

GroupBy describe 格式化 #

groupby.describe() 的輸出格式現在將 describe() 指標標記在列中而不是索引中。此格式與一次應用多個函式時 groupby.agg() 的格式一致。( GH 4792)

先前行為

In [1]: df = pd.DataFrame({'A': [1, 1, 2, 2], 'B': [1, 2, 3, 4]})

In [2]: df.groupby('A').describe()
Out[2]:
                B
A
1 count  2.000000
  mean   1.500000
  std    0.707107
  min    1.000000
  25%    1.250000
  50%    1.500000
  75%    1.750000
  max    2.000000
2 count  2.000000
  mean   3.500000
  std    0.707107
  min    3.000000
  25%    3.250000
  50%    3.500000
  75%    3.750000
  max    4.000000

In [3]: df.groupby('A').agg(["mean", "std", "min", "max"])
Out[3]:
     B
  mean       std amin amax
A
1  1.5  0.707107    1    2
2  3.5  0.707107    3    4

新行為

In [76]: df = pd.DataFrame({'A': [1, 1, 2, 2], 'B': [1, 2, 3, 4]})

In [77]: df.groupby('A').describe()
Out[77]: 
      B                                          
  count mean       std  min   25%  50%   75%  max
A                                                
1   2.0  1.5  0.707107  1.0  1.25  1.5  1.75  2.0
2   2.0  3.5  0.707107  3.0  3.25  3.5  3.75  4.0

In [78]: df.groupby('A').agg(["mean", "std", "min", "max"])
Out[78]: 
     B                  
  mean       std min max
A                       
1  1.5  0.707107   1   2
2  3.5  0.707107   3   4

視窗二進位制 corr/cov 操作返回 MultiIndex DataFrame #

當對 .rolling(..).expanding(..).ewm(..) 物件進行操作時,二進位制視窗操作,如 .corr().cov(),現在將返回一個 2 級 MultiIndexed DataFrame 而不是 Panel,因為 Panel 現在已棄用,請參閱 此處。它們在功能上是等效的,但 MultiIndexed DataFrame 在 pandas 中擁有更多的支援。有關更多資訊,請參閱 視窗二進位制操作 部分。( GH 15677)

In [79]: np.random.seed(1234)

In [80]: df = pd.DataFrame(np.random.rand(100, 2),
   ....:                   columns=pd.Index(['A', 'B'], name='bar'),
   ....:                   index=pd.date_range('20160101',
   ....:                                       periods=100, freq='D', name='foo'))
   ....: 

In [81]: df.tail()
Out[81]: 
bar                A         B
foo                           
2016-04-05  0.640880  0.126205
2016-04-06  0.171465  0.737086
2016-04-07  0.127029  0.369650
2016-04-08  0.604334  0.103104
2016-04-09  0.802374  0.945553

先前行為

In [2]: df.rolling(12).corr()
Out[2]:
<class 'pandas.core.panel.Panel'>
Dimensions: 100 (items) x 2 (major_axis) x 2 (minor_axis)
Items axis: 2016-01-01 00:00:00 to 2016-04-09 00:00:00
Major_axis axis: A to B
Minor_axis axis: A to B

新行為

In [82]: res = df.rolling(12).corr()

In [83]: res.tail()
Out[83]: 
bar                    A         B
foo        bar                    
2016-04-07 B   -0.132090  1.000000
2016-04-08 A    1.000000 -0.145775
           B   -0.145775  1.000000
2016-04-09 A    1.000000  0.119645
           B    0.119645  1.000000

檢索橫截面的相關性矩陣

In [84]: df.rolling(12).corr().loc['2016-04-07']
Out[84]: 
bar        A        B
bar                  
A    1.00000 -0.13209
B   -0.13209  1.00000

HDFStore where 字串比較 #

在先前版本中,大多數型別都可以與 HDFStore 中的字串列進行比較,通常會導致無效比較,返回一個空結果幀。這些比較現在將引發 TypeError (GH 15492)

In [85]: df = pd.DataFrame({'unparsed_date': ['2014-01-01', '2014-01-01']})

In [86]: df.to_hdf('store.h5', key='key', format='table', data_columns=True)

In [87]: df.dtypes
Out[87]: 
unparsed_date    str
dtype: object

先前行為

In [4]: pd.read_hdf('store.h5', 'key', where='unparsed_date > ts')
File "<string>", line 1
  (unparsed_date > 1970-01-01 00:00:01.388552400)
                        ^
SyntaxError: invalid token

新行為

In [18]: ts = pd.Timestamp('2014-01-01')

In [19]: pd.read_hdf('store.h5', 'key', where='unparsed_date > ts')
TypeError: Cannot compare 2014-01-01 00:00:00 of
type <class 'pandas.tslib.Timestamp'> to string column

Index.intersection 和內連線現在保留左側 Index 的順序 #

Index.intersection() 現在保留呼叫 Index (左側) 的順序,而不是其他 Index (右側) 的順序 (GH 15582)。這會影響內連線、DataFrame.join()merge(),以及 .align 方法。

  • Index.intersection

    In [88]: left = pd.Index([2, 1, 0])
    
    In [89]: left
    Out[89]: Index([2, 1, 0], dtype='int64')
    
    In [90]: right = pd.Index([1, 2, 3])
    
    In [91]: right
    Out[91]: Index([1, 2, 3], dtype='int64')
    

    先前行為

    In [4]: left.intersection(right)
    Out[4]: Int64Index([1, 2], dtype='int64')
    

    新行為

    In [92]: left.intersection(right)
    Out[92]: Index([2, 1], dtype='int64')
    
  • DataFrame.joinpd.merge

    In [93]: left = pd.DataFrame({'a': [20, 10, 0]}, index=[2, 1, 0])
    
    In [94]: left
    Out[94]: 
        a
    2  20
    1  10
    0   0
    
    In [95]: right = pd.DataFrame({'b': [100, 200, 300]}, index=[1, 2, 3])
    
    In [96]: right
    Out[96]: 
         b
    1  100
    2  200
    3  300
    

    先前行為

    In [4]: left.join(right, how='inner')
    Out[4]:
       a    b
    1  10  100
    2  20  200
    

    新行為

    In [97]: left.join(right, how='inner')
    Out[97]: 
        a    b
    2  20  200
    1  10  100
    

Pivot table 始終返回 DataFrame #

pivot_table() 的文件指出,它總是返回一個 DataFrame。這裡修復了一個錯誤,該錯誤允許在某些情況下返回 Series。( GH 4386)

In [98]: df = pd.DataFrame({'col1': [3, 4, 5],
   ....:                    'col2': ['C', 'D', 'E'],
   ....:                    'col3': [1, 3, 9]})
   ....: 

In [99]: df
Out[99]: 
   col1 col2  col3
0     3    C     1
1     4    D     3
2     5    E     9

先前行為

In [2]: df.pivot_table('col1', index=['col3', 'col2'], aggfunc="sum")
Out[2]:
col3  col2
1     C       3
3     D       4
9     E       5
Name: col1, dtype: int64

新行為

In [100]: df.pivot_table('col1', index=['col3', 'col2'], aggfunc="sum")
Out[100]: 
           col1
col3 col2      
1    C        3
3    D        4
9    E        5

其他 API 更改#

  • 現在要求 numexpr 版本為 >= 2.4.6,如果此要求未滿足,則根本不會使用它 (GH 15213)。

  • pd.read_csv() 中的 CParserError 已重新命名為 ParserError,並將在未來版本中刪除 (GH 12665)

  • SparseArray.cumsum()SparseSeries.cumsum() 現在將分別始終返回 SparseArraySparseSeries (GH 12855)

  • 使用空 DataFrameDataFrame.applymap() 將返回空 DataFrame 的副本,而不是 Series (GH 8222)

  • Series.map() 現在尊重具有 __missing__ 方法的字典子類的預設值,例如 collections.Counter (GH 15999)

  • .loc 在接受迭代器和 NamedTuples 方面與 .ix 具有相容性 (GH 15120)

  • interpolate()fillna() 如果 limit 關鍵字引數不大於 0,將引發 ValueError。( GH 9217)

  • pd.read_csv() 現在將在 dialect 引數和使用者提供的引數之間存在衝突值時發出 ParserWarning (GH 14898)

  • pd.read_csv() 現在將為 C 引擎引發 ValueError,如果引用字元大於一個位元組 (GH 11592)

  • inplace 引數現在需要布林值,否則會丟擲 ValueError (GH 14189)

  • pandas.api.types.is_datetime64_ns_dtype 現在將報告 tz-aware dtype 的 True,類似於 pandas.api.types.is_datetime64_any_dtype

  • 如果找不到匹配項,DataFrame.asof() 將返回一個填充了 null 的 Series,而不是標量 NaN (GH 15118)

  • 對 NDFrame 物件增加了對 copy.copy()copy.deepcopy() 函式的特定支援 (GH 15444)

  • Series.sort_values() 接受一個單元素布林列表,以與 DataFrame.sort_values() 的行為保持一致 (GH 15604)

  • category dtype 列的 .merge().join() 現在將在可能的情況下保留 category dtype (GH 10409)

  • SparseDataFrame.default_fill_value 將是 0,先前在 pd.get_dummies(..., sparse=True) 的返回中是 nan (GH 15594)

  • Series.str.match 的預設行為已從提取組更改為匹配模式。提取行為自 pandas 版本 0.13.0 起已棄用,可以使用 Series.str.extract 方法完成 (GH 5224)。因此,as_indexer 關鍵字將被忽略(不再需要指定新行為)並已棄用。

  • NaT 現在將對日期時間類布林操作(如 is_month_start)正確報告 False (GH 15781)

  • NaT 現在將為 TimedeltaPeriod 訪問器(如 daysquarter)正確返回 np.nan (GH 15782)

  • NaT 現在將為 tz_localizetz_convert 方法返回 NaT (GH 15830)

  • 具有無效輸入的 DataFramePanel 建構函式現在將引發 ValueError 而不是 PandasError,如果使用標量輸入且沒有軸 (GH 15541)

  • 具有無效輸入的 DataFramePanel 建構函式現在將引發 ValueError 而不是 pandas.core.common.PandasError,如果使用標量輸入且沒有軸;PandasError 異常也已刪除。( GH 15541)

  • 已刪除異常 pandas.core.common.AmbiguousIndexError,因為它未被引用 (GH 15541)

庫的重組:隱私更改 #

模組隱私已更改 #

一些以前公開的 python/c/c++/cython 擴充套件模組已被移動和/或重新命名。這些都已從公共 API 中刪除。此外,pandas.corepandas.compatpandas.util 的頂級模組現在被視為私有。如果指示,引用這些模組時將發出棄用警告。( GH 12588)

先前位置

新位置

已棄用

pandas.lib

pandas._libs.lib

X

pandas.tslib

pandas._libs.tslib

X

pandas.computation

pandas.core.computation

X

pandas.msgpack

pandas.io.msgpack

pandas.index

pandas._libs.index

pandas.algos

pandas._libs.algos

pandas.hashtable

pandas._libs.hashtable

pandas.indexes

pandas.core.indexes

pandas.json

pandas._libs.json / pandas.io.json

X

pandas.parser

pandas._libs.parsers

X

pandas.formats

pandas.io.formats

pandas.sparse

pandas.core.sparse

pandas.tools

pandas.core.reshape

X

pandas.types

pandas.core.dtypes

X

pandas.io.sas.saslib

pandas.io.sas._sas

pandas._join

pandas._libs.join

pandas._hash

pandas._libs.hashing

pandas._period

pandas._libs.period

pandas._sparse

pandas._libs.sparse

pandas._testing

pandas._libs.testing

pandas._window

pandas._libs.window

建立了一些新的子包,其中包含未直接暴露在頂層名稱空間中的公共功能:pandas.errorspandas.plottingpandas.testing(更多細節如下)。與 pandas.api.types 以及 pandas.iopandas.tseries 子模組中的某些函式一起,這些現在是公共子包。

其他更改

  • 現在可以從 pandas.api.types 匯入函式 union_categoricals(),以前是從 pandas.types.concat 匯入的 (GH 15998)

  • 型別匯入 pandas.tslib.NaTType 已棄用,可以使用 type(pandas.NaT) 替代 (GH 16146)

  • pandas.tools.hashing 中的公共函式已從該位置棄用,但現在可以從 pandas.util 匯入 (GH 16223)

  • pandas.util 中的模組:decoratorsprint_versionsdoctoolsvalidatorsdepr_module 現在是私有的。只有 pandas.util 本身中公開的函式才是公共的 (GH 16223)

pandas.errors#

我們正在新增一個標準的公共模組,用於所有 pandas 異常和警告 pandas.errors。( GH 14800)。先前這些異常和警告可以從 pandas.core.commonpandas.io.common 匯入。這些異常和警告將在未來的版本中從 *.common 位置刪除。( GH 15541)

以下現在是此 API 的一部分

['DtypeWarning',
 'EmptyDataError',
 'OutOfBoundsDatetime',
 'ParserError',
 'ParserWarning',
 'PerformanceWarning',
 'UnsortedIndexError',
 'UnsupportedFunctionCall']

pandas.testing#

我們正在新增一個標準模組,該模組公開了 pandas.testing 中的公共測試函式(GH 9895)。這些函式可在編寫使用 pandas 物件的函式功能的測試時使用。

以下測試函式現已成為此 API 的一部分

pandas.plotting#

已添加了一個新的公共 pandas.plotting 模組,其中包含以前位於 pandas.tools.plotting 或頂層名稱空間中的繪圖功能。有關更多詳細資訊,請參閱 棄用部分

其他開發更改#

  • 現在,使用 cython >= 0.23 構建用於開發的 pandas 需要(GH 14831

  • 要求 cython 版本至少為 0.23,以避免出現字元編碼問題(GH 14699

  • 已將測試框架切換為使用 pytestGH 13097

  • 對測試目錄佈局的重新組織(GH 14854GH 15707)。

棄用#

棄用 .ix#

已棄用 .ix 索引器,轉而使用更嚴格的 .iloc.loc 索引器。.ix 在推斷使用者想要做什麼方面提供了很多神奇的功能。更具體地說,.ix 可以根據索引的資料型別,選擇按*位置*或按*標籤*進行索引。這多年來引起了很多使用者困惑。完整的索引文件在此處 此處。(GH 14218

推薦的索引方法是

  • .loc,如果您想按*標籤*索引

  • .iloc,如果您想按*位置*索引。

現在使用 .ix 將顯示一個 DeprecationWarning,其中包含指向一些如何轉換程式碼的示例的連結,此處

In [101]: df = pd.DataFrame({'A': [1, 2, 3],
   .....:                    'B': [4, 5, 6]},
   .....:                   index=list('abc'))
   .....: 

In [102]: df
Out[102]: 
   A  B
a  1  4
b  2  5
c  3  6

以前的行為,即您希望在“A”列中獲取第 0 個和第 2 個元素。

In [3]: df.ix[[0, 2], 'A']
Out[3]:
a    1
c    3
Name: A, dtype: int64

使用 .loc。在這裡,我們將選擇索引中的適當索引,然後使用*標籤*索引。

In [103]: df.loc[df.index[[0, 2]], 'A']
Out[103]: 
a    1
c    3
Name: A, dtype: int64

使用 .iloc。在這裡,我們將獲取“A”列的位置,然後使用*位置*索引來選擇內容。

In [104]: df.iloc[[0, 2], df.columns.get_loc('A')]
Out[104]: 
a    1
c    3
Name: A, dtype: int64

棄用 Panel#

Panel 已棄用,將在將來版本中移除。表示 3-D 資料的推薦方法是使用 DataFrame 上的 MultiIndex,透過 to_frame() 方法,或使用 xarray 包。pandas 提供了一個 to_xarray() 方法來自動化此轉換(GH 13563)。

In [133]: import pandas._testing as tm

In [134]: p = tm.makePanel()

In [135]: p
Out[135]:
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 3 (major_axis) x 4 (minor_axis)
Items axis: ItemA to ItemC
Major_axis axis: 2000-01-03 00:00:00 to 2000-01-05 00:00:00
Minor_axis axis: A to D

轉換為 MultiIndex DataFrame

In [136]: p.to_frame()
Out[136]:
                     ItemA     ItemB     ItemC
major      minor
2000-01-03 A      0.628776 -1.409432  0.209395
           B      0.988138 -1.347533 -0.896581
           C     -0.938153  1.272395 -0.161137
           D     -0.223019 -0.591863 -1.051539
2000-01-04 A      0.186494  1.422986 -0.592886
           B     -0.072608  0.363565  1.104352
           C     -1.239072 -1.449567  0.889157
           D      2.123692 -0.414505 -0.319561
2000-01-05 A      0.952478 -2.147855 -1.473116
           B     -0.550603 -0.014752 -0.431550
           C      0.139683 -1.195524  0.288377
           D      0.122273 -1.425795 -0.619993

[12 rows x 3 columns]

轉換為 xarray DataArray

In [137]: p.to_xarray()
Out[137]:
<xarray.DataArray (items: 3, major_axis: 3, minor_axis: 4)>
array([[[ 0.628776,  0.988138, -0.938153, -0.223019],
        [ 0.186494, -0.072608, -1.239072,  2.123692],
        [ 0.952478, -0.550603,  0.139683,  0.122273]],

       [[-1.409432, -1.347533,  1.272395, -0.591863],
        [ 1.422986,  0.363565, -1.449567, -0.414505],
        [-2.147855, -0.014752, -1.195524, -1.425795]],

       [[ 0.209395, -0.896581, -0.161137, -1.051539],
        [-0.592886,  1.104352,  0.889157, -0.319561],
        [-1.473116, -0.43155 ,  0.288377, -0.619993]]])
Coordinates:
  * items       (items) object 'ItemA' 'ItemB' 'ItemC'
  * major_axis  (major_axis) datetime64[ns] 2000-01-03 2000-01-04 2000-01-05
  * minor_axis  (minor_axis) object 'A' 'B' 'C' 'D'

棄用使用字典進行重新命名時的 groupby.agg() #

`.groupby(..).agg(..)`, `.rolling(..).agg(..)` 和 `.resample(..).agg(..)` 語法可以接受各種輸入,包括標量、列表以及列名到標量或列表的字典。這為構建多個(可能不同的)聚合提供了有用的語法。

但是,`.agg(..)`*也可以*接受一個允許重新命名結果列的字典。這是一種複雜且令人困惑的語法,並且在 `Series` 和 `DataFrame` 之間不一致。我們正在棄用此“重新命名”功能。

  • 我們正在棄用將字典傳遞給分組/滾動/重取樣 Series。這允許您重新命名結果聚合,但這與將字典傳遞給分組 DataFrame 具有完全不同的含義,後者接受列到聚合的對映。

  • 我們正在以類似的方式棄用將字典的字典傳遞給分組/滾動/重取樣 DataFrame

這是一個說明性示例

In [105]: df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
   .....:                    'B': range(5),
   .....:                    'C': range(5)})
   .....: 

In [106]: df
Out[106]: 
   A  B  C
0  1  0  0
1  1  1  1
2  1  2  2
3  2  3  3
4  2  4  4

這是計算不同列的不同聚合的典型有用語法。這是一種自然且有用的語法。我們透過獲取指定列並將函式列表應用於它們來從字典到列表進行聚合。這將返回一個列的 MultiIndex(這*不*被棄用)。

In [107]: df.groupby('A').agg({'B': 'sum', 'C': 'min'})
Out[107]: 
   B  C
A      
1  3  0
2  7  3

以下是第一個棄用的示例,將字典傳遞給分組的 Series。這是一個聚合與重新命名的組合

In [6]: df.groupby('A').B.agg({'foo': 'count'})
FutureWarning: using a dict on a Series for aggregation
is deprecated and will be removed in a future version

Out[6]:
   foo
A
1    3
2    2

您可以透過以下方式更慣用地完成相同的操作

In [108]: df.groupby('A').B.agg(['count']).rename(columns={'count': 'foo'})
Out[108]: 
   foo
A     
1    3
2    2

以下是第二個棄用的示例,將字典的字典傳遞給分組的 DataFrame

In [23]: (df.groupby('A')
    ...:    .agg({'B': {'foo': 'sum'}, 'C': {'bar': 'min'}})
    ...:  )
FutureWarning: using a dict with renaming is deprecated and
will be removed in a future version

Out[23]:
     B   C
   foo bar
A
1   3   0
2   7   3

您幾乎可以透過以下方式完成相同的操作

In [109]: (df.groupby('A')
   .....:    .agg({'B': 'sum', 'C': 'min'})
   .....:    .rename(columns={'B': 'foo', 'C': 'bar'})
   .....:  )
   .....: 
Out[109]: 
   foo  bar
A          
1    3    0
2    7    3

棄用 .plotting#

已棄用 pandas.tools.plotting 模組,轉而使用頂層 pandas.plotting 模組。所有公共繪圖函式現在都可以從 pandas.plotting 匯入(GH 12548)。

此外,頂層 pandas.scatter_matrixpandas.plot_params 已棄用。使用者也可以從 pandas.plotting 匯入它們。

以前的指令碼

pd.tools.plotting.scatter_matrix(df)
pd.scatter_matrix(df)

應更改為

pd.plotting.scatter_matrix(df)

其他棄用#

  • SparseArray.to_dense() 已棄用 fill 引數,因為該引數未被尊重(GH 14647

  • SparseSeries.to_dense() 已棄用 sparse_only 引數(GH 14647

  • Series.repeat() 已棄用 reps 引數,轉而使用 repeatsGH 12662

  • 對於 dtype 引數,Series 建構函式和 .astype 方法已棄用接受沒有頻率的時間戳 dtype(例如 np.datetime64)(GH 15524

  • Index.repeat()MultiIndex.repeat() 已棄用 n 引數,轉而使用 repeatsGH 12662

  • Categorical.searchsorted()Series.searchsorted() 已棄用 v 引數,轉而使用 valueGH 12662

  • TimedeltaIndex.searchsorted()DatetimeIndex.searchsorted()PeriodIndex.searchsorted() 已棄用 key 引數,轉而使用 valueGH 12662

  • DataFrame.astype() 已棄用 raise_on_error 引數,轉而使用 errorsGH 14878

  • Series.sortlevelDataFrame.sortlevel 已棄用,轉而使用 Series.sort_indexDataFrame.sort_indexGH 15099

  • pandas.tools.merge 匯入 concat 已棄用,轉而從 pandas 名稱空間匯入。這隻會影響顯式匯入(GH 15358

  • Series/DataFrame/Panel.consolidate() 已棄用為公共方法。(GH 15483

  • Series.str.match()as_indexer 關鍵字已棄用(忽略的關鍵字)(GH 15257)。

  • 以下頂層 pandas 函式已棄用,將在將來版本中移除(GH 13790GH 15940

    • pd.pnow(),由 Period.now() 替換

    • pd.Term,已移除,因為它不適用於使用者程式碼。在 HDFStore 中搜索時,請改用 where 子句中的內聯字串表示式

    • pd.Expr,已移除,因為它不適用於使用者程式碼。

    • pd.match(),已移除。

    • pd.groupby(),由直接在 Series/DataFrame 上使用 .groupby() 方法替換

    • pd.get_store(),由直接呼叫 pd.HDFStore(...) 替換

  • pandas.api.types 棄用 is_any_int_dtypeis_floating_dtypeis_sequenceGH 16042

移除先前版本的棄用/更改#

  • 已移除 pandas.rpy 模組。類似的功能可以透過 rpy2 專案訪問。有關更多詳細資訊,請參閱 R 介面文件

  • 已移除帶有 google-analytics 介面的 pandas.io.ga 模組(GH 11308)。類似的功能可以在 Google2Pandas 包中找到。

  • pd.to_datetimepd.to_timedelta 已棄用 coerce 引數,轉而使用 errorsGH 13602

  • 已移除 pandas.stats.fama_macbethpandas.stats.olspandas.stats.plmpandas.stats.var,以及頂層的 pandas.fama_macbethpandas.ols 例程。類似的功能可以在 statsmodels 包中找到。(GH 11898

  • 已移除 TimeSeriesSparseTimeSeries 類(`Series` 和 `SparseSeries` 的別名)(GH 10890GH 15098)。

  • 已棄用 Series.is_time_series,轉而使用 Series.index.is_all_datesGH 15098

  • 已棄用方法 irowicoligetiget_value 已移除,轉而使用 ilociat,如此處所述(GH 10711)。

  • 已棄用的 DataFrame.iterkv() 已移除,轉而使用 DataFrame.iteritems()GH 10711

  • Categorical 建構函式已移除 name 引數(GH 10632

  • Categorical 已停止支援 NaN 類別(GH 10748

  • 已從 duplicated()drop_duplicates()nlargest()nsmallest() 方法中移除了 take_last 引數(GH 10236GH 10792GH 10920

  • 已從 SeriesIndexDataFrame 中移除了 sortorder 方法(GH 10726

  • pytables 中的 where 子句僅接受字串和表示式型別,而不接受其他資料型別(GH 12027

  • 已從 DataFrame 中移除 combineAddcombineMult 方法,分別轉而使用 addmulGH 10735

效能改進#

  • 改進了 pd.wide_to_long() 的效能(GH 14779

  • 透過在推斷為字串的 object dtype 上釋放 GIL,改進了 pd.factorize() 的效能(GH 14859GH 16057

  • 當使用不規則的 DatetimeIndex(或 compat_x=True)進行時間序列繪圖時,效能得到改進(GH 15073)。

  • 改進了 groupby().cummin()groupby().cummax() 的效能(GH 15048GH 15109GH 15561GH 15635

  • 使用 MultiIndex 進行索引時,效能得到改進,記憶體佔用減少(GH 15245

  • read_sas() 方法中讀取緩衝區物件時,如果沒有指定格式,將推斷檔案路徑字串而不是緩衝區物件。(GH 14947

  • 改進了分類資料的 .rank() 效能(GH 15498

  • 使用 .unstack() 時效能得到改進(GH 15503

  • 改進了 category 列上合併/連線的效能(GH 10409

  • 改進了 drop_duplicates()bool 列上的效能(GH 12963

  • 當應用函式使用組 DataFrame 的 .name 屬性時,改進了 pd.core.groupby.GroupBy.apply 的效能(GH 15062)。

  • 使用列表或陣列進行 iloc 索引時,效能得到改進(GH 15504)。

  • 在具有單調索引的 Series.sort_index() 上,效能得到改進(GH 15694

  • 在某些平臺上的 pd.read_csv() 中,透過緩衝讀取提高了效能(GH 16039

Bug 修復#

轉換#

  • Timestamp.replace 中的錯誤,現在當給出錯誤的引數名稱時會引發 TypeError;以前這會引發 ValueErrorGH 15240

  • Timestamp.replace 中進行長期整數傳遞的相容性錯誤(GH 15030

  • Timestamp 中,當提供了時區時,返回基於 UTC 的時間/日期屬性的錯誤(GH 13303GH 6538

  • Timestamp 中,在構造期間錯誤地本地化時區的錯誤(GH 11481GH 15777

  • TimedeltaIndex 加法中的錯誤,其中溢位被允許而沒有錯誤(GH 14816

  • TimedeltaIndex 中,當使用 loc 進行布林索引時引發 ValueError 的錯誤(GH 14946

  • Timestamp + Timedelta/Offset 操作中捕獲溢位的錯誤(GH 15126

  • DatetimeIndex.round()Timestamp.round() 中,在按毫秒或更少進行四捨五入時,浮點精度錯誤(GH 14440GH 15578

  • astype() 中的錯誤,其中 inf 值被錯誤地轉換為整數。現在,對於 Series 和 DataFrames,使用 astype() 會引發錯誤(GH 14265

  • DataFrame(..).apply(to_numeric) 中,當值為 decimal.Decimal 型別時出現的錯誤。(GH 14827

  • describe() 中,當將不包含中位數的 NumPy 陣列傳遞給 percentiles 關鍵字引數時出現的錯誤(GH 14908

  • 清理了 PeriodIndex 建構函式,包括更一致地在浮點數上引發錯誤(GH 13277

  • 在使用空 NDFrame 物件進行 __deepcopy__ 時的錯誤(GH 15370

  • .replace() 中可能導致錯誤 dtype 的錯誤。(GH 12747GH 15765

  • Series.replaceDataFrame.replace 中,對於空替換字典失敗的錯誤(GH 15289

  • Series.replace 中,用數字替換字串的錯誤(GH 15743

  • 在指定整數 dtype 和包含 NaN 元素的 Index 建構函式中的錯誤(GH 15187

  • 在具有 datetimetzSeries 建構函式中的錯誤(GH 14928

  • Series.dt.round() 中,對不同引數的 NaT 的行為不一致的錯誤(GH 14940

  • 在同時提供 copy=Truedtype 引數的 Series 建構函式中的錯誤(GH 15125

  • 與常量相比,對於空 DataFrame 的比較方法(例如 ltgt 等)返回的 Series 的 dtype 不正確(GH 15077

  • 在包含帶時區日期的混合 dtype 的 Series.ffill() 中的錯誤。(GH 14956

  • DataFrame.fillna() 中,當 fillna 值是 dict 型別時,忽略 downcast 引數的錯誤(GH 15277

  • .asfreq() 中,對於空 Series 未設定頻率的錯誤(GH 14320

  • 在帶有 null 和日期時間的列表狀 DataFrame 建構函式中的錯誤(GH 15869

  • 在處理帶時區日期的 DataFrame.fillna() 中的錯誤(GH 15855

  • is_string_dtypeis_timedelta64_ns_dtypeis_string_like_dtype 中,當傳入 None 時引發錯誤的錯誤(GH 15941

  • pd.uniqueCategorical 上的返回型別錯誤,它返回了一個 ndarray 而不是 CategoricalGH 15903

  • Index.to_series() 中,索引未被複制(因此稍後修改會更改原始索引)的錯誤(GH 15949

  • 在使用長度為 1 的 DataFrame 進行部分字串索引時的錯誤(GH 16071

  • Series 建構函式中,傳遞無效 dtype 未引發錯誤的錯誤。(GH 15520

索引#

  • Index 的反向運算元冪運算中的錯誤(GH 14973

  • DataFrame.sort_values() 中,按多列排序時,其中一列為 int64 型別且包含 NaT 的錯誤(GH 14922

  • DataFrame.reindex() 中,當傳遞 columns 時忽略 method 的錯誤(GH 14992

  • DataFrame.loc 中,使用 Series 索引器索引 MultiIndex 時的錯誤(GH 14730GH 15424

  • DataFrame.loc 中,使用 NumPy 陣列索引 MultiIndex 時的錯誤(GH 15434

  • Series.asof 中,當 Series 包含所有 np.nan 時引發錯誤的錯誤(GH 15713

  • 在選擇帶時區感知的列時,使用 .at 的錯誤(GH 15822

  • Series.where() 和 DataFrame.where() 中的錯誤,陣列狀條件被拒絕 (GH 15414)

  • Series.where() 中的錯誤,時區感知資料被轉換為浮點數表示 (GH 15701)

  • .loc 中的錯誤,對於 DataFrame 的標量訪問不會返回正確的 dtype (GH 11617)

  • MultiIndex 輸出格式中的錯誤,當名稱為整數時 (GH 12223, GH 15262)

  • Categorical.searchsorted() 中的錯誤,使用了字母順序而不是提供的分類順序 (GH 14522)

  • Series.iloc 中的錯誤,當 list-like 索引輸入為 Categorical 物件時,返回了 Categorical 物件,但預期是 Series。 (GH 14580)

  • DataFrame.isin() 中的錯誤,將 datetimelike 與空 frame 進行比較 (GH 15473)

  • .reset_index() 中的錯誤,當 MultiIndex 的全 NaN 層時會失敗 (GH 6322)

  • .reset_index() 中的錯誤,當為 MultiIndex 列中已存在的索引名稱引發錯誤時 (GH 16120)

  • 使用元組建立 MultiIndex 時,未傳遞名稱列表的錯誤;現在會引發 ValueError (GH 15110)

  • MultiIndex 和截斷的 HTML 顯示中的錯誤 (GH 14882)

  • .info() 顯示中的錯誤,當 MultiIndex 只包含非字串時,會始終顯示限定符 (+) (GH 15245)

  • pd.concat() 中的錯誤,當組合具有 MultiIndex 的 DataFrame 時,未正確處理結果 DataFrame 的 MultiIndex 名稱,當輸入 DataFrame 的 MultiIndex 名稱中存在 None 時 (GH 15787)

  • DataFrame.sort_index() 和 Series.sort_index() 中的錯誤,na_position 與 MultiIndex 不相容 (GH 14784, GH 16604)

  • pd.concat() 中的錯誤,當組合具有 CategoricalIndex 的物件時 (GH 16111)

  • 使用標量和 CategoricalIndex 進行索引中的錯誤 (GH 16123)

IO#

  • pd.to_numeric() 中的錯誤,浮點數和無符號整數元素被不正確地轉換 (GH 14941, GH 15005)

  • pd.read_fwf() 中的錯誤,在列寬推斷期間未遵守 skiprows 引數 (GH 11256)

  • pd.read_csv() 中的錯誤,在處理前未驗證 dialect 引數 (GH 14898)

  • pd.read_csv() 中的錯誤,在使用 usecols 時,缺失資料被不正確地處理 (GH 6710)

  • pd.read_csv() 中的錯誤,包含一個有很多列的行,然後是列數較少的行的檔案會導致崩潰 (GH 14125)

  • pd.read_csv() 的 C 引擎中的錯誤,當 usecols 與 parse_dates 一起使用時,索引不正確 (GH 14792)

  • pd.read_csv() 中的錯誤,在使用 parse_dates 和多行標題時 (GH 15376)

  • pd.read_csv() 中的錯誤,使用 float_precision='round_trip' 時,當解析文字條目時會導致段錯誤 (GH 15140)

  • pd.read_csv() 中的錯誤,當指定了索引但未指定任何值作為 null 值時 (GH 15835)

  • pd.read_csv() 中的錯誤,某些無效檔案物件導致 Python 直譯器崩潰 (GH 15337)

  • pd.read_csv() 中的錯誤,允許 nrows 和 chunksize 的無效值 (GH 15767)

  • pd.read_csv() 的 Python 引擎中的錯誤,在發生解析錯誤時顯示了無用的錯誤訊息 (GH 15910)

  • pd.read_csv() 中的錯誤,skipfooter 引數未被正確驗證 (GH 15925)

  • pd.to_csv() 中的錯誤,在寫入時間戳索引時發生數值溢位 (GH 15982)

  • pd.util.hashing.hash_pandas_object() 中的錯誤,分類資料的雜湊取決於類別的順序,而不是僅僅取決於其值。 (GH 15143)

  • .to_json() 中的錯誤,當 lines=True 且內容(鍵或值)包含跳脫字元時 (GH 15096)

  • .to_json() 中的錯誤,導致單位元組 ASCII 字元被擴充套件為四位元組 Unicode (GH 15344)

  • .to_json() 的 C 引擎中的錯誤,當 frac 為奇數且 diff 為 0.5 時,未正確處理回滾 (GH 15716, GH 15864)

  • pd.read_json() 在 Python 2 中使用 lines=True 且內容包含非 ASCII Unicode 字元時的錯誤 (GH 15132)

  • pd.read_msgpack() 中的錯誤,Series 的分類資料被不正確地處理 (GH 14901)

  • pd.read_msgpack() 中的錯誤,不允許載入具有 CategoricalIndex 索引的 DataFrame (GH 15487)

  • pd.read_msgpack() 在反序列化 CategoricalIndex 時的錯誤 (GH 15487)

  • DataFrame.to_records() 中的錯誤,在轉換具有時區的 DatetimeIndex 時 (GH 13937)

  • DataFrame.to_records() 中的錯誤,在列名包含 Unicode 字元時失敗 (GH 11879)

  • .to_sql() 中的錯誤,在寫入具有數字索引名稱的 DataFrame 時 (GH 15404).

  • DataFrame.to_html() 中的錯誤,當 index=False 和 max_rows 一起使用時,會引發 IndexError (GH 14998)

  • pd.read_hdf() 中的錯誤,當 where 引數傳遞了 Timestamp 且列不是日期型別時 (GH 15492)

  • DataFrame.to_stata() 和 StataWriter 中的錯誤,為某些區域生成格式不正確的檔案 (GH 13856)

  • StataReader 和 StataWriter 中的錯誤,允許無效的編碼 (GH 15723)

  • Series repr 格式化中的錯誤,當輸出被截斷時未顯示長度 (GH 15962).

繪圖#

  • DataFrame.hist 中的錯誤,plt.tight_layout 導致 AttributeError (使用 matplotlib >= 2.0.1) (GH 9351)

  • DataFrame.boxplot 中的錯誤,fontsize 未應用於兩個軸上的刻度標籤 (GH 15108)

  • pandas 註冊到 matplotlib 的日期和時間轉換器中的錯誤,未處理多維資料 (GH 16026)

  • pd.scatter_matrix() 中的錯誤,可以接受 color 或 c,但不能同時接受兩者 (GH 14855)

GroupBy/resample/rolling

  • .groupby(..).resample() 中的錯誤,當傳遞 on= 關鍵字引數時 (GH 15021)

  • 正確設定 Groupby.* 函式的 __name__ 和 __qualname__ (GH 14620)

  • GroupBy.get_group() 中的錯誤,在使用分類分組器時失敗 (GH 15155)

  • .groupby(...).rolling(...) 中的錯誤,當指定 on 並使用 DatetimeIndex 時 (GH 15130, GH 13966)

  • groupby 操作中,當傳遞 numeric_only=False 時,與 timedelta64 的互動錯誤 (GH 5724)

  • groupby.apply() 中的錯誤,當並非所有值都是數值時,將 object dtypes 強制轉換為數值型別 (GH 14423, GH 15421, GH 15670)

  • resample 中的錯誤,當重取樣時間序列時,非字串 loffset 引數不會被應用 (GH 13218)

  • DataFrame.groupby().describe() 在對包含元組的 Index 進行分組時的錯誤 (GH 14848)

  • groupby().nunique() 與 datetimelike-grouper 的錯誤,箱子的計數不正確 (GH 13453)

  • groupby.transform() 中的錯誤,會將結果的 dtypes 強制轉換回原始型別 (GH 10972, GH 11444)

  • groupby.agg() 中的錯誤,不正確地本地化 datetime 的時區 (GH 15426, GH 10668, GH 13046)

  • .rolling/expanding() 函式中的錯誤,count() 未計算 np.Inf,也未處理 object dtypes (GH 12541)

  • .rolling() 中的錯誤,pd.Timedelta 或 datetime.timedelta 不被接受為 window 引數 (GH 15440)

  • Rolling.quantile 函式中的錯誤,當呼叫具有超出 [0, 1] 範圍的分位數時導致段錯誤 (GH 15463)

  • DataFrame.resample().median() 中的錯誤,如果存在重複的列名 (GH 14233)

Sparse#

  • SparseSeries.reindex() 中的錯誤,在單層上使用長度為 1 的列表時 (GH 15447)

  • 在對 SparseDataFrame 的某個 Series (的副本) 設定值後,SparseDataFrame 的 repr 格式化中的錯誤 (GH 15488)

  • SparseDataFrame 使用列表構造時的錯誤,未強制轉換為 dtype (GH 15682)

  • 稀疏陣列索引中的錯誤,索引未被驗證 (GH 15863)

Reshaping#

  • pd.merge_asof() 中的錯誤,當指定多個 by 時,left_index 或 right_index 導致失敗 (GH 15676)

  • pd.merge_asof() 中的錯誤,當指定 tolerance 時,left_index/right_index 一起使用導致失敗 (GH 15135)

  • DataFrame.pivot_table() 中的錯誤,當 dropna=True 時,對於 category dtype 的列,不會刪除全 NaN 列 (GH 15193)

  • pd.melt() 中的錯誤,當為 value_vars 傳遞元組值時導致 TypeError (GH 15348)

  • pd.pivot_table() 中的錯誤,當 values 引數不在列中時未引發錯誤 (GH 14938)

  • pd.concat() 中的錯誤,當與空 DataFrame 進行連線時,join='inner' 的處理不正確 (GH 15328)

  • DataFrame.join 和 pd.merge 中 sort=True 時,當基於索引進行連線時的錯誤 (GH 15582)

  • DataFrame.nsmallest 和 DataFrame.nlargest 中的錯誤,當值相同時導致重複行 (GH 15297)

  • pandas.pivot_table() 中的錯誤,當為 margins 關鍵字傳遞 Unicode 輸入時,會錯誤地引發 UnicodeError (GH 13292)

數值#

  • .rank() 中的錯誤,不正確地對有序分類進行排名 (GH 15420)

  • .corr() 和 .cov() 中的錯誤,當列和索引是同一個物件時 (GH 14617)

  • .mode() 中的錯誤,當模式只有一個值時未返回模式 (GH 15714)

  • pd.cut() 中的錯誤,當對全為 0 的陣列使用單個 bin 時 (GH 15428)

  • pd.qcut() 中的錯誤,當使用單個分位數且陣列具有相同值時 (GH 15431)

  • pandas.tools.utils.cartesian_product() 在 Windows 上處理大輸入時可能導致溢位 (GH 15265)

  • .eval() 中的錯誤,導致多行求值在非第一行的區域性變數處失敗 (GH 15342)

其他#

  • 與 SciPy 0.19.0 的相容性,用於 .interpolate() 的測試 (GH 15662)

  • 32 位平臺的相容性,用於 .qcut/cut;bins 現在將是 int64 dtype (GH 14866)

  • 與 Qt 的互動錯誤,當 QtApplication 已存在時 (GH 14372)

  • 避免在 import pandas 時使用 np.finfo(),以減輕 Python GIL 誤用導致的死鎖 (GH 14641)

貢獻者#

本次釋出共有 204 人貢獻了補丁。名字旁有“+”號的人是首次貢獻補丁。

  • Adam J. Stewart +

  • Adrian +

  • Ajay Saxena

  • Akash Tandon +

  • Albert Villanova del Moral +

  • Aleksey Bilogur +

  • Alexis Mignon +

  • Amol Kahat +

  • Andreas Winkler +

  • Andrew Kittredge +

  • Anthonios Partheniou

  • Arco Bast +

  • Ashish Singal +

  • Baurzhan Muftakhidinov +

  • Ben Kandel

  • Ben Thayer +

  • Ben Welsh +

  • Bill Chambers +

  • Brandon M. Burroughs

  • Brian +

  • Brian McFee +

  • Carlos Souza +

  • Chris

  • Chris Ham

  • Chris Warth

  • Christoph Gohlke

  • Christoph Paulik +

  • Christopher C. Aycock

  • Clemens Brunner +

  • D.S. McNeil +

  • DaanVanHauwermeiren +

  • Daniel Himmelstein

  • Dave Willmer

  • David Cook +

  • David Gwynne +

  • David Hoffman +

  • David Krych

  • Diego Fernandez +

  • Dimitris Spathis +

  • Dmitry L +

  • Dody Suria Wijaya +

  • Dominik Stanczak +

  • Dr-Irv

  • Dr. Irv +

  • Elliott Sales de Andrade +

  • Ennemoser Christoph +

  • Francesc Alted +

  • Fumito Hamamura +

  • Giacomo Ferroni

  • Graham R. Jeffries +

  • Greg Williams +

  • Guilherme Beltramini +

  • Guilherme Samora +

  • Hao Wu +

  • Harshit Patni +

  • Ilya V. Schurov +

  • Iván Vallés Pérez

  • Jackie Leng +

  • Jaehoon Hwang +

  • James Draper +

  • James Goppert +

  • James McBride +

  • James Santucci +

  • Jan Schulz

  • Jeff Carey

  • Jeff Reback

  • JennaVergeynst +

  • Jim +

  • Jim Crist

  • Joe Jevnik

  • Joel Nothman +

  • John +

  • John Tucker +

  • John W. O’Brien

  • John Zwinck

  • Jon M. Mease

  • Jon Mease

  • Jonathan Whitmore +

  • Jonathan de Bruin +

  • Joost Kranendonk +

  • Joris Van den Bossche

  • Joshua Bradt +

  • Julian Santander

  • Julien Marrec +

  • Jun Kim +

  • Justin Solinsky +

  • Kacawi +

  • Kamal Kamalaldin +

  • Kerby Shedden

  • Kernc

  • Keshav Ramaswamy

  • Kevin Sheppard

  • Kyle Kelley

  • Larry Ren

  • Leon Yin +

  • Line Pedersen +

  • Lorenzo Cestaro +

  • Luca Scarabello

  • Lukasz +

  • Mahmoud Lababidi

  • Mark Mandel +

  • Matt Roeschke

  • Matthew Brett

  • Matthew Roeschke +

  • Matti Picus

  • Maximilian Roos

  • Michael Charlton +

  • Michael Felt

  • Michael Lamparski +

  • Michiel Stock +

  • Mikolaj Chwalisz +

  • Min RK

  • Miroslav Šedivý +

  • Mykola Golubyev

  • Nate Yoder

  • Nathalie Rud +

  • Nicholas Ver Halen

  • Nick Chmura +

  • Nolan Nichols +

  • Pankaj Pandey +

  • Pawel Kordek

  • Pete Huang +

  • Peter +

  • Peter Csizsek +

  • Petio Petrov +

  • Phil Ruffwind +

  • Pietro Battiston

  • Piotr Chromiec

  • Prasanjit Prakash +

  • Rob Forgione +

  • Robert Bradshaw

  • Robin +

  • Rodolfo Fernandez

  • Roger Thomas

  • Rouz Azari +

  • Sahil Dua

  • Sam Foo +

  • Sami Salonen +

  • Sarah Bird +

  • Sarma Tangirala +

  • Scott Sanderson

  • Sebastian Bank

  • Sebastian Gsänger +

  • Shawn Heide

  • Shyam Saladi +

  • Sinhrks

  • Stephen Rauch +

  • Sébastien de Menten +

  • Tara Adiseshan

  • Thiago Serafim

  • Thoralf Gutierrez +

  • Thrasibule +

  • Tobias Gustafsson +

  • Tom Augspurger

  • Tong SHEN +

  • Tong Shen +

  • TrigonaMinima +

  • Uwe +

  • Wes Turner

  • Wiktor Tomczak +

  • WillAyd

  • Yaroslav Halchenko

  • Yimeng Zhang +

  • abaldenko +

  • adrian-stepien +

  • alexandercbooth +

  • atbd +

  • bastewart +

  • bmagnusson +

  • carlosdanielcsantos +

  • chaimdemulder +

  • chris-b1

  • dickreuter +

  • discort +

  • dr-leo +

  • dubourg

  • dwkenefick +

  • funnycrab +

  • gfyoung

  • goldenbull +

  • hesham.shabana@hotmail.com

  • jojomdt +

  • linebp +

  • manu +

  • manuels +

  • mattip +

  • maxalbert +

  • mcocdawc +

  • nuffe +

  • paul-mannino

  • pbreach +

  • sakkemo +

  • scls19fr

  • sinhrks

  • stijnvanhoey +

  • the-nose-knows +

  • themrmax +

  • tomrod +

  • tzinckgraf

  • wandersoncferreira

  • watercrossing +

  • wcwagner

  • xgdgsc +

  • yui-knk