バージョン 0.18.0 (2016年3月13日)#
これは 0.17.1 からのメジャーリリースであり、少数の API 変更、いくつかの新機能、機能強化、パフォーマンス改善に加え、多数のバグ修正が含まれています。すべてのユーザーにこのバージョンへのアップグレードをお勧めします。
警告
numexpr バージョン 2.4.4 は、バグのある動作のため、警告が表示され、pandas の計算バックエンドとして使用されなくなります。これは他のバージョン (>= 2.1 および >= 2.4.6) には影響しません。 (GH 12489)
主な機能は以下の通りです。
移動ウィンドウ関数と拡張ウィンドウ関数は、
.groupbyと同様に、Series と DataFrame のメソッドになりました。詳細については、こちらを参照してください。メモリ節約のための
Int64Indexの特殊な形式としてRangeIndexのサポートが追加されました。詳細については、こちらを参照してください。.resampleメソッドの API に破壊的変更があり、より.groupbyのようになりました。詳細については、こちらを参照してください。0.14.0 から非推奨とされていた浮動小数点数による位置インデックスのサポートが削除されました。これにより
TypeErrorが発生するようになります。詳細については、こちらを参照してください。.to_xarray()関数が xarray パッケージとの互換性のために追加されました。詳細については、こちらを参照してください。read_sas関数がsas7bdatファイルを読み込むように強化されました。詳細については、こちらを参照してください。.str.extractall() メソッドの追加、および .str.extract() メソッドと .str.cat() メソッドの API 変更。
pd.test()トップレベルの nose テストランナーが利用可能になりました (GH 4327)。
更新する前に、API 変更と 非推奨事項を確認してください。
v0.18.0 の新機能
新機能#
ウィンドウ関数がメソッドになりました#
ウィンドウ関数は、トップレベル関数ではなく、Series/DataFrame オブジェクトのメソッドとしてリファクタリングされ、トップレベル関数は非推奨となりました。これにより、これらのウィンドウ型関数は .groupby と同様の API を持つことができます。完全なドキュメントについては こちら を参照してください (GH 11603, GH 12373)
In [1]: np.random.seed(1234)
In [2]: df = pd.DataFrame({'A': range(10), 'B': np.random.randn(10)})
In [3]: df
Out[3]:
A B
0 0 0.471435
1 1 -1.190976
2 2 1.432707
3 3 -0.312652
4 4 -0.720589
5 5 0.887163
6 6 0.859588
7 7 -0.636524
8 8 0.015696
9 9 -2.242685
[10 rows x 2 columns]
以前の動作
In [8]: pd.rolling_mean(df, window=3)
FutureWarning: pd.rolling_mean is deprecated for DataFrame and will be removed in a future version, replace with
DataFrame.rolling(window=3,center=False).mean()
Out[8]:
A B
0 NaN NaN
1 NaN NaN
2 1 0.237722
3 2 -0.023640
4 3 0.133155
5 4 -0.048693
6 5 0.342054
7 6 0.370076
8 7 0.079587
9 8 -0.954504
新しい動作
In [4]: r = df.rolling(window=3)
これらは記述的な repr を表示します。
In [5]: r
Out[5]: Rolling [window=3,center=False,axis=0,method=single]
利用可能なメソッドとプロパティのタブ補完付き。
In [9]: r.<TAB> # noqa E225, E999
r.A r.agg r.apply r.count r.exclusions r.max r.median r.name r.skew r.sum
r.B r.aggregate r.corr r.cov r.kurt r.mean r.min r.quantile r.std r.var
メソッドは Rolling オブジェクト自体に対して操作します
In [6]: r.mean()
Out[6]:
A B
0 NaN NaN
1 NaN NaN
2 1.0 0.237722
3 2.0 -0.023640
4 3.0 0.133155
5 4.0 -0.048693
6 5.0 0.342054
7 6.0 0.370076
8 7.0 0.079587
9 8.0 -0.954504
[10 rows x 2 columns]
これらは getitem アクセサーを提供します
In [7]: r['A'].mean()
Out[7]:
0 NaN
1 NaN
2 1.0
3 2.0
4 3.0
5 4.0
6 5.0
7 6.0
8 7.0
9 8.0
Name: A, Length: 10, dtype: float64
そして複数の集約
In [8]: r.agg({'A': ['mean', 'std'],
...: 'B': ['mean', 'std']})
...:
Out[8]:
A B
mean std mean std
0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
2 1.0 1.0 0.237722 1.327364
3 2.0 1.0 -0.023640 1.335505
4 3.0 1.0 0.133155 1.143778
5 4.0 1.0 -0.048693 0.835747
6 5.0 1.0 0.342054 0.920379
7 6.0 1.0 0.370076 0.871850
8 7.0 1.0 0.079587 0.750099
9 8.0 1.0 -0.954504 1.162285
[10 rows x 4 columns]
rename の変更点#
Series.rename および NDFrame.rename_axis は、以前のラベルを変更する動作に加えて、Series または軸の*名前*を変更するために、スカラまたはリストのような引数を受け取るようになりました。 (GH 9494, GH 11965)
In [9]: s = pd.Series(np.random.randn(5))
In [10]: s.rename('newname')
Out[10]:
0 1.150036
1 0.991946
2 0.953324
3 -2.021255
4 -0.334077
Name: newname, Length: 5, dtype: float64
In [11]: df = pd.DataFrame(np.random.randn(5, 2))
In [12]: (df.rename_axis("indexname")
....: .rename_axis("columns_name", axis="columns"))
....:
Out[12]:
columns_name 0 1
indexname
0 0.002118 0.405453
1 0.289092 1.321158
2 -1.546906 -0.202646
3 -0.655969 0.193421
4 0.553439 1.318152
[5 rows x 2 columns]
新しい機能はメソッドチェーンでうまく機能します。以前は、これらのメソッドは*ラベル*を新しいラベルにマッピングする関数または辞書のみを受け入れていました。これは関数または辞書のような値に対しては以前と同じように機能し続けます。
レンジインデックス#
Int64Index のサブクラスとして RangeIndex が追加され、一般的なユースケースでのメモリ節約の代替手段をサポートします。これは、Python の range オブジェクト (Python 2 の xrange) と同様の実装で、インデックスの開始、停止、ステップ値のみを格納します。必要に応じて Int64Index に変換されるため、ユーザー API と透過的に連携します。
これは、以前の Int64Index ではなく、NDFrame オブジェクトのデフォルトの構築済みインデックスになります。 (GH 939, GH 12070, GH 12071, GH 12109, GH 12888)
以前の動作
In [3]: s = pd.Series(range(1000))
In [4]: s.index
Out[4]:
Int64Index([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
990, 991, 992, 993, 994, 995, 996, 997, 998, 999], dtype='int64', length=1000)
In [6]: s.index.nbytes
Out[6]: 8000
新しい動作
In [13]: s = pd.Series(range(1000))
In [14]: s.index
Out[14]: RangeIndex(start=0, stop=1000, step=1)
In [15]: s.index.nbytes
Out[15]: 128
str.extract の変更点#
.str.extract メソッドは、キャプチャグループを持つ正規表現を受け取り、各対象文字列内の最初のマッチを見つけ、キャプチャグループの内容を返します (GH 11386)。
v0.18.0 では、expand 引数が extract に追加されました。
expand=False: 対象と正規表現パターンに応じて、Series、Index、またはDataFrameを返します (0.18.0 以前と同じ動作)。expand=True: 常にDataFrameを返します。これはユーザーの観点からより一貫性があり、わかりやすくなります。
現在、デフォルトは expand=None で、FutureWarning が表示され、expand=False が使用されます。この警告を避けるには、expand を明示的に指定してください。
In [1]: pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=None)
FutureWarning: currently extract(expand=None) means expand=False (return Index/Series/DataFrame)
but in a future version of pandas this will be changed to expand=True (return DataFrame)
Out[1]:
0 1
1 2
2 NaN
dtype: object
1つのグループを持つ正規表現を抽出する場合、expand=False であれば Series を返します。
In [16]: pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=False)
Out[16]:
0 1
1 2
2 NaN
Length: 3, dtype: object
expand=True の場合、1つの列を持つ DataFrame を返します。
In [17]: pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=True)
Out[17]:
0
0 1
1 2
2 NaN
[3 rows x 1 columns]
正確に1つのキャプチャグループを持つ正規表現で Index を呼び出す場合、expand=False であれば Index を返します。
In [18]: s = pd.Series(["a1", "b2", "c3"], ["A11", "B22", "C33"])
In [19]: s.index
Out[19]: Index(['A11', 'B22', 'C33'], dtype='object')
In [20]: s.index.str.extract("(?P<letter>[a-zA-Z])", expand=False)
Out[20]: Index(['A', 'B', 'C'], dtype='object', name='letter')
expand=True の場合、1つの列を持つ DataFrame を返します。
In [21]: s.index.str.extract("(?P<letter>[a-zA-Z])", expand=True)
Out[21]:
letter
0 A
1 B
2 C
[3 rows x 1 columns]
複数のキャプチャグループを持つ正規表現で Index を呼び出す場合、expand=False であれば ValueError が発生します。
>>> s.index.str.extract("(?P<letter>[a-zA-Z])([0-9]+)", expand=False)
ValueError: only one regex group is supported with Index
expand=True の場合、DataFrame を返します。
In [22]: s.index.str.extract("(?P<letter>[a-zA-Z])([0-9]+)", expand=True)
Out[22]:
letter 1
0 A 11
1 B 22
2 C 33
[3 rows x 2 columns]
要約すると、extract(expand=True) は常に、すべての対象文字列に行、すべてのキャプチャグループに列を持つ DataFrame を返します。
str.extractall の追加#
.str.extractall メソッドが追加されました (GH 11386)。最初のマッチのみを返す extract とは異なります。
In [23]: s = pd.Series(["a1a2", "b1", "c1"], ["A", "B", "C"])
In [24]: s
Out[24]:
A a1a2
B b1
C c1
Length: 3, dtype: object
In [25]: s.str.extract(r"(?P<letter>[ab])(?P<digit>\d)", expand=False)
Out[25]:
letter digit
A a 1
B b 1
C NaN NaN
[3 rows x 2 columns]
extractall メソッドはすべてのマッチを返します。
In [26]: s.str.extractall(r"(?P<letter>[ab])(?P<digit>\d)")
Out[26]:
letter digit
match
A 0 a 1
1 a 2
B 0 b 1
[3 rows x 2 columns]
str.cat の変更点#
.str.cat() メソッドは Series の要素を連結します。以前は、Series に NaN 値が存在する場合、.str.cat() を呼び出すと NaN が返されましたが、これは他の Series.str.* API とは異なりました。この動作は、デフォルトで NaN 値を無視するように修正されました。 (GH 11435)。
sep をキーワード引数ではなく引数として指定するという誤りを防ぐため、新しい、より親切な ValueError が追加されました。 (GH 11334)。
In [27]: pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ')
Out[27]: 'a b c'
In [28]: pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ', na_rep='?')
Out[28]: 'a b ? c'
In [2]: pd.Series(['a', 'b', np.nan, 'c']).str.cat(' ')
ValueError: Did you mean to supply a ``sep`` keyword?
日時型丸め#
DatetimeIndex, Timestamp, TimedeltaIndex, Timedelta は、日時のような丸め、切り捨て、切り上げのための .round(), .floor(), .ceil() メソッドを獲得しました。 (GH 4314, GH 11963)
ナイーブな日時
In [29]: dr = pd.date_range('20130101 09:12:56.1234', periods=3)
In [30]: dr
Out[30]:
DatetimeIndex(['2013-01-01 09:12:56.123400', '2013-01-02 09:12:56.123400',
'2013-01-03 09:12:56.123400'],
dtype='datetime64[ns]', freq='D')
In [31]: dr.round('s')
Out[31]:
DatetimeIndex(['2013-01-01 09:12:56', '2013-01-02 09:12:56',
'2013-01-03 09:12:56'],
dtype='datetime64[ns]', freq=None)
# Timestamp scalar
In [32]: dr[0]
Out[32]: Timestamp('2013-01-01 09:12:56.123400')
In [33]: dr[0].round('10s')
Out[33]: Timestamp('2013-01-01 09:13:00')
タイムゾーン対応はローカルタイムで丸め、切り捨て、切り上げされます。
In [34]: dr = dr.tz_localize('US/Eastern')
In [35]: dr
Out[35]:
DatetimeIndex(['2013-01-01 09:12:56.123400-05:00',
'2013-01-02 09:12:56.123400-05:00',
'2013-01-03 09:12:56.123400-05:00'],
dtype='datetime64[ns, US/Eastern]', freq=None)
In [36]: dr.round('s')
Out[36]:
DatetimeIndex(['2013-01-01 09:12:56-05:00', '2013-01-02 09:12:56-05:00',
'2013-01-03 09:12:56-05:00'],
dtype='datetime64[ns, US/Eastern]', freq=None)
Timedeltas
In [37]: t = pd.timedelta_range('1 days 2 hr 13 min 45 us', periods=3, freq='d')
In [38]: t
Out[38]:
TimedeltaIndex(['1 days 02:13:00.000045', '2 days 02:13:00.000045',
'3 days 02:13:00.000045'],
dtype='timedelta64[ns]', freq='D')
In [39]: t.round('10min')
Out[39]: TimedeltaIndex(['1 days 02:10:00', '2 days 02:10:00', '3 days 02:10:00'], dtype='timedelta64[ns]', freq=None)
# Timedelta scalar
In [40]: t[0]
Out[40]: Timedelta('1 days 02:13:00.000045')
In [41]: t[0].round('2h')
Out[41]: Timedelta('1 days 02:00:00')
さらに、.round()、.floor()、および .ceil() は Series の .dt アクセサーを介して利用可能になります。
In [42]: s = pd.Series(dr)
In [43]: s
Out[43]:
0 2013-01-01 09:12:56.123400-05:00
1 2013-01-02 09:12:56.123400-05:00
2 2013-01-03 09:12:56.123400-05:00
Length: 3, dtype: datetime64[ns, US/Eastern]
In [44]: s.dt.round('D')
Out[44]:
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
Length: 3, dtype: datetime64[ns, US/Eastern]
FloatIndex における整数の書式設定#
FloatIndex 内の整数、例えば 1. は、小数点と 0 の数字、例えば 1.0 でフォーマットされるようになりました (GH 11713)。この変更は、コンソールへの表示だけでなく、.to_csv や .to_html などの IO メソッドの出力にも影響します。
以前の動作
In [2]: s = pd.Series([1, 2, 3], index=np.arange(3.))
In [3]: s
Out[3]:
0 1
1 2
2 3
dtype: int64
In [4]: s.index
Out[4]: Float64Index([0.0, 1.0, 2.0], dtype='float64')
In [5]: print(s.to_csv(path=None))
0,1
1,2
2,3
新しい動作
In [45]: s = pd.Series([1, 2, 3], index=np.arange(3.))
In [46]: s
Out[46]:
0.0 1
1.0 2
2.0 3
Length: 3, dtype: int64
In [47]: s.index
Out[47]: Index([0.0, 1.0, 2.0], dtype='float64')
In [48]: print(s.to_csv(path_or_buf=None, header=False))
0.0,1
1.0,2
2.0,3
dtype 割り当て動作の変更点#
DataFrame のスライスが同じ dtype の新しいスライスで更新された場合、DataFrame の dtype は同じままになります。 (GH 10503)
以前の動作
In [5]: df = pd.DataFrame({'a': [0, 1, 1],
'b': pd.Series([100, 200, 300], dtype='uint32')})
In [7]: df.dtypes
Out[7]:
a int64
b uint32
dtype: object
In [8]: ix = df['a'] == 1
In [9]: df.loc[ix, 'b'] = df.loc[ix, 'b']
In [11]: df.dtypes
Out[11]:
a int64
b int64
dtype: object
新しい動作
In [49]: df = pd.DataFrame({'a': [0, 1, 1],
....: 'b': pd.Series([100, 200, 300], dtype='uint32')})
....:
In [50]: df.dtypes
Out[50]:
a int64
b uint32
Length: 2, dtype: object
In [51]: ix = df['a'] == 1
In [52]: df.loc[ix, 'b'] = df.loc[ix, 'b']
In [53]: df.dtypes
Out[53]:
a int64
b uint32
Length: 2, dtype: object
DataFrame の整数スライスが、精度を失うことなく整数にダウンキャストできる可能性のある新しい浮動小数点数スライスで部分的に更新された場合、スライスの dtype は整数ではなく浮動小数点数に設定されます。
以前の動作
In [4]: df = pd.DataFrame(np.array(range(1,10)).reshape(3,3),
columns=list('abc'),
index=[[4,4,8], [8,10,12]])
In [5]: df
Out[5]:
a b c
4 8 1 2 3
10 4 5 6
8 12 7 8 9
In [7]: df.ix[4, 'c'] = np.array([0., 1.])
In [8]: df
Out[8]:
a b c
4 8 1 2 0
10 4 5 1
8 12 7 8 9
新しい動作
In [54]: df = pd.DataFrame(np.array(range(1,10)).reshape(3,3),
....: columns=list('abc'),
....: index=[[4,4,8], [8,10,12]])
....:
In [55]: df
Out[55]:
a b c
4 8 1 2 3
10 4 5 6
8 12 7 8 9
[3 rows x 3 columns]
In [56]: df.loc[4, 'c'] = np.array([0., 1.])
In [57]: df
Out[57]:
a b c
4 8 1 2 0
10 4 5 1
8 12 7 8 9
[3 rows x 3 columns]
to_xarray メソッド#
将来の pandas バージョンでは、Panel およびその他の 2 次元のオブジェクトは非推奨になります。連続性を提供するために、すべての NDFrame オブジェクトには .to_xarray() メソッドが追加され、2 次元を超える xarray オブジェクトに変換できるようになりました。この xarray は pandas に似たインターフェースを持っています。 (GH 11972)
xarray の完全なドキュメントはこちらを参照してください。
In [1]: p = Panel(np.arange(2*3*4).reshape(2,3,4))
In [2]: p.to_xarray()
Out[2]:
<xarray.DataArray (items: 2, major_axis: 3, minor_axis: 4)>
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
Coordinates:
* items (items) int64 0 1
* major_axis (major_axis) int64 0 1 2
* minor_axis (minor_axis) int64 0 1 2 3
Latex 表現#
DataFrame は、nbconvert を使用して ipython/jupyter ノートブックで latex に変換できるように、._repr_latex_() メソッドを獲得しました。 (GH 11778)
これは、オプション pd.display.latex.repr=True を設定することで有効にする必要があることに注意してください (GH 12182)
たとえば、nbconvert を使用して Jupyter ノートブックを Latex に変換する予定がある場合、最初のセルに pd.display.latex.repr=True ステートメントを配置すると、含まれる DataFrame 出力も Latex として保存されます。
オプション display.latex.escape と display.latex.longtable も設定に追加され、to_latex メソッドによって自動的に使用されます。詳細については、利用可能なオプションのドキュメントを参照してください。
pd.read_sas() の変更点#
read_sas は、圧縮ファイルを含む SAS7BDAT ファイルを読み込む機能を得ました。ファイルは全体を読み込むことも、増分的に読み込むこともできます。詳細については、こちらを参照してください。 (GH 4052)
その他の機能強化#
SAS xport ファイルの切り捨てられた浮動小数点数を処理 (GH 11713)
Series.to_stringでインデックスを非表示にするオプションを追加 (GH 11729)read_excelはs3://bucketname/filename形式の s3 URL をサポートするようになりました (GH 11447)s3 から読み込む際の
AWS_S3_HOST環境変数のサポートを追加 (GH 12198)Panel.round()の単純なバージョンが実装されました (GH 11763)Python 3.x の場合、
round(DataFrame)、round(Series)、round(Panel)が動作します (GH 11763)sys.getsizeof(obj)は、pandas オブジェクトのメモリ使用量 (含まれる値を含む) を返します (GH 11597)Seriesはis_unique属性を獲得しました (GH 11946)DataFrame.quantileとSeries.quantileがinterpolationキーワードを受け入れるようになりました (GH 10174)。セル値のより柔軟な書式設定のために
DataFrame.style.formatを追加 (GH 11692)DataFrame.select_dtypesがnp.float16型コードを許可するようになりました (GH 11990)pivot_table()がvaluesパラメータにほとんどのイテラブルを受け入れるようになりました (GH 12017)Google
BigQueryサービスアカウント認証のサポートを追加しました。これにより、リモートサーバーでの認証が可能になります。 (GH 11881, GH 12572)。詳細については こちら を参照してください。HDFStoreがイテラブルになりました:for k in storeはfor k in store.keys()と同等です (GH 12221)。Periodの.dtに不足しているメソッド/フィールドを追加 (GH 8848)コードベース全体が
PEP-化されました (GH 12096)
下位互換性のない API の変更#
.to_string(index=False)メソッドの出力から先頭の空白が削除されました (GH 11833)outパラメータがSeries.round()メソッドから削除されました。 (GH 11763)DataFrame.round()は、非数値列を返り値で変更せずに残し、例外を発生させません。 (GH 11885)DataFrame.head(0)およびDataFrame.tail(0)はselfではなく空のフレームを返します。 (GH 11937)Series.head(0)およびSeries.tail(0)はselfではなく空のシリーズを返します。 (GH 11937)to_msgpackとread_msgpackのエンコーディングがデフォルトで'utf-8'になりました。 (GH 12170)テキストファイル解析関数 (
.read_csv(),.read_table(),.read_fwf()) のキーワード引数の順序が、関連する引数をグループ化するように変更されました。 (GH 11555)NaTType.isoformatは文字列'NaT'を返すようになり、結果をTimestampのコンストラクタに渡せるようになりました。 (GH 12300)
NaT および Timedelta 演算#
NaT と Timedelta は算術演算を拡張し、該当する場合は Series 算術演算にも適用されます。datetime64[ns] または timedelta64[ns] に対して定義されていた演算は、NaT に対しても定義されるようになりました (GH 11564)。
NaT は整数および浮動小数点数との算術演算をサポートするようになりました。
In [58]: pd.NaT * 1
Out[58]: NaT
In [59]: pd.NaT * 1.5
Out[59]: NaT
In [60]: pd.NaT / 2
Out[60]: NaT
In [61]: pd.NaT * np.nan
Out[61]: NaT
NaT は datetime64[ns] および timedelta64[ns] とのより多くの算術演算を定義します。
In [62]: pd.NaT / pd.NaT
Out[62]: nan
In [63]: pd.Timedelta('1s') / pd.NaT
Out[63]: nan
NaT は datetime64[ns] または timedelta64[ns] のいずれかの null を表すことができます。曖昧さがあるため、timedelta64[ns] として扱われ、より多くの演算が成功するようになります。
In [64]: pd.NaT + pd.NaT
Out[64]: NaT
# same as
In [65]: pd.Timedelta('1s') + pd.Timedelta('1s')
Out[65]: Timedelta('0 days 00:00:02')
対照的に
In [3]: pd.Timestamp('19900315') + pd.Timestamp('19900315')
TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp'
ただし、dtype が datetime64[ns] または timedelta64[ns] である Series にラップされている場合、dtype 情報は尊重されます。
In [1]: pd.Series([pd.NaT], dtype='<M8[ns]') + pd.Series([pd.NaT], dtype='<M8[ns]')
TypeError: can only operate on a datetimes for subtraction,
but the operator [__add__] was passed
In [66]: pd.Series([pd.NaT], dtype='<m8[ns]') + pd.Series([pd.NaT], dtype='<m8[ns]')
Out[66]:
0 NaT
Length: 1, dtype: timedelta64[ns]
Timedelta の floats による除算が動作するようになりました。
In [67]: pd.Timedelta('1s') / 2.0
Out[67]: Timedelta('0 days 00:00:00.500000')
Series 内の Timedelta による Timestamp の減算が動作します (GH 11925)
In [68]: ser = pd.Series(pd.timedelta_range('1 day', periods=3))
In [69]: ser
Out[69]:
0 1 days
1 2 days
2 3 days
Length: 3, dtype: timedelta64[ns]
In [70]: pd.Timestamp('2012-01-01') - ser
Out[70]:
0 2011-12-31
1 2011-12-30
2 2011-12-29
Length: 3, dtype: datetime64[ns]
NaT.isoformat() は 'NaT' を返すようになりました。この変更により、pd.Timestamp は isoformat からあらゆるタイムスタンプのようなオブジェクトを再構成できるようになります (GH 12300)。
msgpack の変更点#
0.17.0 から 0.18.0 にかけて msgpack の書き込み形式に将来的に互換性のない変更が行われました。古いバージョンの pandas は新しいバージョンでパックされたファイルを読み込むことができません (GH 12129, GH 10527)
0.17.0 で導入され、0.18.0 で修正された to_msgpack と read_msgpack のバグにより、Python 2 でパックされたファイルが Python 3 で読み込めなくなりました (GH 12142)。以下の表は、msgpack の下位および上位互換性について説明しています。
警告
パック元 |
アンパック可能 |
|---|---|
0.17 以前 / Python 2 |
すべて |
0.17 以前 / Python 3 |
すべて |
0.17 / Python 2 |
|
0.17 / Python 3 |
>=0.18 / 任意の Python |
0.18 |
>= 0.18 |
0.18.0 は、古いバージョンでパックされたファイルを読み込むための後方互換性がありますが、Python 2 で 0.17 でパックされたファイルは例外で、Python 2 でのみアンパックできます。
.rank のシグネチャ変更#
Series.rank と DataFrame.rank が同じシグネチャを持つようになりました (GH 11759)
以前のシグネチャ
In [3]: pd.Series([0,1]).rank(method='average', na_option='keep',
ascending=True, pct=False)
Out[3]:
0 1
1 2
dtype: float64
In [4]: pd.DataFrame([0,1]).rank(axis=0, numeric_only=None,
method='average', na_option='keep',
ascending=True, pct=False)
Out[4]:
0
0 1
1 2
新しいシグネチャ
In [71]: pd.Series([0,1]).rank(axis=0, method='average', numeric_only=False,
....: na_option='keep', ascending=True, pct=False)
....:
Out[71]:
0 1.0
1 2.0
Length: 2, dtype: float64
In [72]: pd.DataFrame([0,1]).rank(axis=0, method='average', numeric_only=False,
....: na_option='keep', ascending=True, pct=False)
....:
Out[72]:
0
0 1.0
1 2.0
[2 rows x 1 columns]
n=0 の QuarterBegin のバグ#
以前のバージョンでは、n パラメータが 0 の場合、QuarterBegin オフセットの動作は日付によって一貫性がありませんでした。 (GH 11406)
n=0 のアンカー付きオフセットの一般的な意味論は、日付がアンカーポイント (例: 四半期の開始日) の場合、日付を移動せず、それ以外の場合は次のアンカーポイントに繰り上げるということです。
In [73]: d = pd.Timestamp('2014-02-01')
In [74]: d
Out[74]: Timestamp('2014-02-01 00:00:00')
In [75]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[75]: Timestamp('2014-02-01 00:00:00')
In [76]: d + pd.offsets.QuarterBegin(n=0, startingMonth=1)
Out[76]: Timestamp('2014-04-01 00:00:00')
以前のバージョンの QuarterBegin オフセットでは、日付が四半期の開始日と同じ月の場合、日付は*後方*にロールバックされました。
In [3]: d = pd.Timestamp('2014-02-15')
In [4]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[4]: Timestamp('2014-02-01 00:00:00')
この動作はバージョン 0.18.0 で修正され、MonthBegin や YearBegin のような他のアンカー付きオフセットと一貫しています。
In [77]: d = pd.Timestamp('2014-02-15')
In [78]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[78]: Timestamp('2014-05-01 00:00:00')
リサンプル API#
上記のウィンドウ関数 API の変更と同様に、.resample(...) は、より groupby ライクな API を持つように変更されています。 (GH 11732, GH 12702, GH 12202, GH 12332, GH 12334, GH 12348, GH 12448)。
In [79]: np.random.seed(1234)
In [80]: df = pd.DataFrame(np.random.rand(10,4),
....: columns=list('ABCD'),
....: index=pd.date_range('2010-01-01 09:00:00',
....: periods=10, freq='s'))
....:
In [81]: df
Out[81]:
A B C D
2010-01-01 09:00:00 0.191519 0.622109 0.437728 0.785359
2010-01-01 09:00:01 0.779976 0.272593 0.276464 0.801872
2010-01-01 09:00:02 0.958139 0.875933 0.357817 0.500995
2010-01-01 09:00:03 0.683463 0.712702 0.370251 0.561196
2010-01-01 09:00:04 0.503083 0.013768 0.772827 0.882641
2010-01-01 09:00:05 0.364886 0.615396 0.075381 0.368824
2010-01-01 09:00:06 0.933140 0.651378 0.397203 0.788730
2010-01-01 09:00:07 0.316836 0.568099 0.869127 0.436173
2010-01-01 09:00:08 0.802148 0.143767 0.704261 0.704581
2010-01-01 09:00:09 0.218792 0.924868 0.442141 0.909316
[10 rows x 4 columns]
以前の API:
すぐに評価されるリサンプリング操作を記述しました。how パラメータが指定されていない場合、デフォルトで how='mean' になりました。
In [6]: df.resample('2s')
Out[6]:
A B C D
2010-01-01 09:00:00 0.485748 0.447351 0.357096 0.793615
2010-01-01 09:00:02 0.820801 0.794317 0.364034 0.531096
2010-01-01 09:00:04 0.433985 0.314582 0.424104 0.625733
2010-01-01 09:00:06 0.624988 0.609738 0.633165 0.612452
2010-01-01 09:00:08 0.510470 0.534317 0.573201 0.806949
how を直接指定することもできました。
In [7]: df.resample('2s', how='sum')
Out[7]:
A B C D
2010-01-01 09:00:00 0.971495 0.894701 0.714192 1.587231
2010-01-01 09:00:02 1.641602 1.588635 0.728068 1.062191
2010-01-01 09:00:04 0.867969 0.629165 0.848208 1.251465
2010-01-01 09:00:06 1.249976 1.219477 1.266330 1.224904
2010-01-01 09:00:08 1.020940 1.068634 1.146402 1.613897
新しい API:
今では、.groupby(...) と同様に、.resample(..) を2段階の操作として記述でき、Resampler を返します。
In [82]: r = df.resample('2s')
In [83]: r
Out[83]: <pandas.core.resample.DatetimeIndexResampler object at 0x7f9440acefe0>
ダウンサンプリング#
次に、このオブジェクトを使用して操作を実行できます。これらはダウンサンプリング操作です(高周波数から低周波数への変換)。
In [84]: r.mean()
Out[84]:
A B C D
2010-01-01 09:00:00 0.485748 0.447351 0.357096 0.793615
2010-01-01 09:00:02 0.820801 0.794317 0.364034 0.531096
2010-01-01 09:00:04 0.433985 0.314582 0.424104 0.625733
2010-01-01 09:00:06 0.624988 0.609738 0.633165 0.612452
2010-01-01 09:00:08 0.510470 0.534317 0.573201 0.806949
[5 rows x 4 columns]
In [85]: r.sum()
Out[85]:
A B C D
2010-01-01 09:00:00 0.971495 0.894701 0.714192 1.587231
2010-01-01 09:00:02 1.641602 1.588635 0.728068 1.062191
2010-01-01 09:00:04 0.867969 0.629165 0.848208 1.251465
2010-01-01 09:00:06 1.249976 1.219477 1.266330 1.224904
2010-01-01 09:00:08 1.020940 1.068634 1.146402 1.613897
[5 rows x 4 columns]
さらに、resample は特定の列に対してリサンプルを実行するための getitem 演算をサポートするようになりました。
In [86]: r[['A','C']].mean()
Out[86]:
A C
2010-01-01 09:00:00 0.485748 0.357096
2010-01-01 09:00:02 0.820801 0.364034
2010-01-01 09:00:04 0.433985 0.424104
2010-01-01 09:00:06 0.624988 0.633165
2010-01-01 09:00:08 0.510470 0.573201
[5 rows x 2 columns]
そして .aggregate 型の操作。
In [87]: r.agg({'A' : 'mean', 'B' : 'sum'})
Out[87]:
A B
2010-01-01 09:00:00 0.485748 0.894701
2010-01-01 09:00:02 0.820801 1.588635
2010-01-01 09:00:04 0.433985 0.629165
2010-01-01 09:00:06 0.624988 1.219477
2010-01-01 09:00:08 0.510470 1.068634
[5 rows x 2 columns]
これらのアクセサーは、もちろん組み合わせることができます
In [88]: r[['A','B']].agg(['mean','sum'])
Out[88]:
A B
mean sum mean sum
2010-01-01 09:00:00 0.485748 0.971495 0.447351 0.894701
2010-01-01 09:00:02 0.820801 1.641602 0.794317 1.588635
2010-01-01 09:00:04 0.433985 0.867969 0.314582 0.629165
2010-01-01 09:00:06 0.624988 1.249976 0.609738 1.219477
2010-01-01 09:00:08 0.510470 1.020940 0.534317 1.068634
[5 rows x 4 columns]
アップサンプリング#
アップサンプリング操作は、より低い周波数からより高い周波数に変換します。これらは現在、Resampler オブジェクトを使用して、backfill()、ffill()、fillna()、asfreq() メソッドで実行されます。
In [89]: s = pd.Series(np.arange(5, dtype='int64'),
index=pd.date_range('2010-01-01', periods=5, freq='Q'))
In [90]: s
Out[90]:
2010-03-31 0
2010-06-30 1
2010-09-30 2
2010-12-31 3
2011-03-31 4
Freq: Q-DEC, Length: 5, dtype: int64
以前
In [6]: s.resample('M', fill_method='ffill')
Out[6]:
2010-03-31 0
2010-04-30 0
2010-05-31 0
2010-06-30 1
2010-07-31 1
2010-08-31 1
2010-09-30 2
2010-10-31 2
2010-11-30 2
2010-12-31 3
2011-01-31 3
2011-02-28 3
2011-03-31 4
Freq: M, dtype: int64
新しい API
In [91]: s.resample('M').ffill()
Out[91]:
2010-03-31 0
2010-04-30 0
2010-05-31 0
2010-06-30 1
2010-07-31 1
2010-08-31 1
2010-09-30 2
2010-10-31 2
2010-11-30 2
2010-12-31 3
2011-01-31 3
2011-02-28 3
2011-03-31 4
Freq: M, Length: 13, dtype: int64
注
新しいAPIでは、ダウンサンプリングまたはアップサンプリングのいずれかを行うことができます。以前の実装では、アップサンプリングを行っているにもかかわらず、アグリゲーター関数(meanなど)を渡すことができ、混乱を招くことがありました。
以前の API は動作しますが、非推奨警告が表示されます#
警告
この resample の新しい API には、0.18.0 以前の API の内部変更が含まれており、ほとんどの場合、リサンプル操作が遅延オブジェクトを返すため、非推奨警告とともに動作します。操作をインターセプトし、(0.18.0 以前の)API が行ったことを(警告付きで)実行できます。一般的な使用例を次に示します。
In [4]: r = df.resample('2s')
In [6]: r*10
pandas/tseries/resample.py:80: FutureWarning: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)
Out[6]:
A B C D
2010-01-01 09:00:00 4.857476 4.473507 3.570960 7.936154
2010-01-01 09:00:02 8.208011 7.943173 3.640340 5.310957
2010-01-01 09:00:04 4.339846 3.145823 4.241039 6.257326
2010-01-01 09:00:06 6.249881 6.097384 6.331650 6.124518
2010-01-01 09:00:08 5.104699 5.343172 5.732009 8.069486
しかし、Resampler に直接アクセスして代入操作を行うと ValueError が発生します。
In [7]: r.iloc[0] = 5
ValueError: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)
新しいAPIでは元のコードを使用した場合にすべての操作を実行できない状況があります。このコードは2秒ごとにリサンプルし、mean を取得し、さらにその結果の min を取得することを意図しています。
In [4]: df.resample('2s').min()
Out[4]:
A 0.433985
B 0.314582
C 0.357096
D 0.531096
dtype: float64
新しい API は
In [89]: df.resample('2s').min()
Out[89]:
A B C D
2010-01-01 09:00:00 0.191519 0.272593 0.276464 0.785359
2010-01-01 09:00:02 0.683463 0.712702 0.357817 0.500995
2010-01-01 09:00:04 0.364886 0.013768 0.075381 0.368824
2010-01-01 09:00:06 0.316836 0.568099 0.397203 0.436173
2010-01-01 09:00:08 0.218792 0.143767 0.442141 0.704581
[5 rows x 4 columns]
良いニュースは、新しい API と古い API で返される次元が異なるため、これは例外を大きく発生させるはずです。
元の操作を再現するには
In [90]: df.resample('2s').mean().min()
Out[90]:
A 0.433985
B 0.314582
C 0.357096
D 0.531096
Length: 4, dtype: float64
eval の変更点#
以前のバージョンでは、eval 式での新しい列の割り当ては、DataFrame に対するインプレース変更となりました。 (GH 9297, GH 8664, GH 10486)
In [91]: df = pd.DataFrame({'a': np.linspace(0, 10, 5), 'b': range(5)})
In [92]: df
Out[92]:
a b
0 0.0 0
1 2.5 1
2 5.0 2
3 7.5 3
4 10.0 4
[5 rows x 2 columns]
In [12]: df.eval('c = a + b')
FutureWarning: eval expressions containing an assignment currentlydefault to operating inplace.
This will change in a future version of pandas, use inplace=True to avoid this warning.
In [13]: df
Out[13]:
a b c
0 0.0 0 0.0
1 2.5 1 3.5
2 5.0 2 7.0
3 7.5 3 10.5
4 10.0 4 14.0
バージョン 0.18.0 では、割り当てをインプレースで行うか、コピーを返すかを選択するための新しい inplace キーワードが追加されました。
In [93]: df
Out[93]:
a b c
0 0.0 0 0.0
1 2.5 1 3.5
2 5.0 2 7.0
3 7.5 3 10.5
4 10.0 4 14.0
[5 rows x 3 columns]
In [94]: df.eval('d = c - b', inplace=False)
Out[94]:
a b c d
0 0.0 0 0.0 0.0
1 2.5 1 3.5 2.5
2 5.0 2 7.0 5.0
3 7.5 3 10.5 7.5
4 10.0 4 14.0 10.0
[5 rows x 4 columns]
In [95]: df
Out[95]:
a b c
0 0.0 0 0.0
1 2.5 1 3.5
2 5.0 2 7.0
3 7.5 3 10.5
4 10.0 4 14.0
[5 rows x 3 columns]
In [96]: df.eval('d = c - b', inplace=True)
In [97]: df
Out[97]:
a b c d
0 0.0 0 0.0 0.0
1 2.5 1 3.5 2.5
2 5.0 2 7.0 5.0
3 7.5 3 10.5 7.5
4 10.0 4 14.0 10.0
[5 rows x 4 columns]
警告
下位互換性のため、指定しない場合 inplace はデフォルトで True になります。これは将来の pandas のバージョンで変更されます。コードがインプレース割り当てに依存している場合は、inplace=True を明示的に設定するように更新する必要があります。
inplace キーワードパラメータも query メソッドに追加されました。
In [98]: df.query('a > 5')
Out[98]:
a b c d
3 7.5 3 10.5 7.5
4 10.0 4 14.0 10.0
[2 rows x 4 columns]
In [99]: df.query('a > 5', inplace=True)
In [100]: df
Out[100]:
a b c d
3 7.5 3 10.5 7.5
4 10.0 4 14.0 10.0
[2 rows x 4 columns]
警告
query における inplace のデフォルト値は False であり、以前のバージョンと一貫していることに注意してください。
eval も複数割り当てのための複数行式を許可するように更新されました。これらの式は順に1つずつ評価されます。複数行式では割り当てのみが有効です。
In [101]: df
Out[101]:
a b c d
3 7.5 3 10.5 7.5
4 10.0 4 14.0 10.0
[2 rows x 4 columns]
In [102]: df.eval("""
.....: e = d + a
.....: f = e - 22
.....: g = f / 2.0""", inplace=True)
.....:
In [103]: df
Out[103]:
a b c d e f g
3 7.5 3 10.5 7.5 15.0 -7.0 -3.5
4 10.0 4 14.0 10.0 20.0 -2.0 -1.0
[2 rows x 7 columns]
その他の API の変更#
DataFrame.between_timeおよびSeries.between_timeは、固定された時間文字列セットのみを解析するようになりました。日付文字列の解析はサポートされなくなり、ValueErrorが発生します。 (GH 11818)In [107]: s = pd.Series(range(10), pd.date_range('2015-01-01', freq='H', periods=10)) In [108]: s.between_time("7:00am", "9:00am") Out[108]: 2015-01-01 07:00:00 7 2015-01-01 08:00:00 8 2015-01-01 09:00:00 9 Freq: H, Length: 3, dtype: int64
これにより、例外が発生します。
In [2]: s.between_time('20150101 07:00:00','20150101 09:00:00') ValueError: Cannot convert arg ['20150101 07:00:00'] to a time.
.memory_usage()は、.info()の memory_usage と同様に、インデックス内の値を含むようになりました (GH 11597)DataFrame.to_latex()は、Python 2 でencodingパラメータを使用することで、非 ASCII エンコーディング (例:utf-8) をサポートするようになりました (GH 7061)pandas.merge()およびDataFrame.merge()は、DataFrame型またはそのサブクラスではないオブジェクトとマージしようとすると、特定のエラーメッセージを表示します (GH 12081)DataFrame.unstackとSeries.unstackは、アンスタックの結果としてDataFrameに欠損値が発生した場合に、欠損値を直接置換できるようにfill_valueキーワードを受け入れるようになりました。追加の利点として、fill_valueを指定すると、元のスタックデータのデータ型が保持されます。 (GH 9746)ウィンドウ関数とリサンプリングの新しいAPIの一部として、集約関数が明確化され、無効な集約に対してより有益なエラーメッセージを出すようになりました。 (GH 9052)。完全な例はgroupbyに示されています。
NDFrameオブジェクトの統計関数(sum(), mean(), min()など)は、**kwargsに numpy と互換性のない引数が渡された場合、例外を発生させるようになりました (GH 12301).to_latexおよび.to_htmlには.to_csvと同様のdecimalパラメータが追加されました。デフォルトは'.'です (GH 12031)空のデータだがインデックスを持つ
DataFrameを構築する際、より分かりやすいエラーメッセージを表示するようになりました (GH 8020).describe()は bool dtype をカテゴリとして適切に処理するようになりました (GH 6625)ユーザー定義の入力を含む無効な
.transformで、より役立つエラーメッセージを表示するようになりました (GH 10165)指数加重関数は、アルファを直接指定できるようになりました (GH 10789)。また、パラメータが
0 < alpha <= 1に違反する場合、ValueErrorを発生させます (GH 12492)。
非推奨#
関数
pd.rolling_*,pd.expanding_*,pd.ewm*は非推奨となり、対応するメソッド呼び出しに置き換えられました。新しい推奨構文にはすべての引数 (デフォルト値であっても) が含まれることに注意してください (GH 11603)In [1]: s = pd.Series(range(3)) In [2]: pd.rolling_mean(s,window=2,min_periods=1) FutureWarning: pd.rolling_mean is deprecated for Series and will be removed in a future version, replace with Series.rolling(min_periods=1,window=2,center=False).mean() Out[2]: 0 0.0 1 0.5 2 1.5 dtype: float64 In [3]: pd.rolling_cov(s, s, window=2) FutureWarning: pd.rolling_cov is deprecated for Series and will be removed in a future version, replace with Series.rolling(window=2).cov(other=<Series>) Out[3]: 0 NaN 1 0.5 2 0.5 dtype: float64
.rolling、.expanding、および.ewm(新規) 関数に対するfreqおよびhow引数は非推奨となり、将来のバージョンで削除されます。ウィンドウ関数を作成する前に、単に入力をリサンプルすることができます。 (GH 11603)。たとえば、ローリング5日ウィンドウの最大値を取得するために
s.rolling(window=5,freq='D').max()の代わりに、s.resample('D').mean().rolling(window=5).max()を使用できます。これは、まずデータを日次データにリサンプルし、次にローリング5日ウィンドウを提供します。pandas.tseries.frequencies.get_offset_name関数は非推奨です。代わりにオフセットの.freqstrプロパティを使用してください (GH 11192)pandas.stats.fama_macbethルーチンは非推奨となり、将来のバージョンで削除されます (GH 6077)pandas.stats.ols,pandas.stats.plm,pandas.stats.varルーチンは非推奨となり、将来のバージョンで削除されます (GH 6077)HDFStore.selectで、where句が文字列型ではない場合に、長らく非推奨とされていた構文を使用すると、DeprecationWarningではなくFutureWarningを表示するようになりました (GH 12027)pandas.options.display.mpl_style設定は非推奨となり、将来の pandas のバージョンで削除されます。この機能は Matplotlib の スタイルシート でより適切に処理されます (GH 11783)。
非推奨の浮動小数点インデクサーの削除#
GH 4892 (バージョン 0.14.0) では、非 Float64Index で浮動小数点数によるインデックス付けが非推奨となりました。0.18.0 では、この非推奨警告が削除され、これらは TypeError を発生させるようになりました。 (GH 12165, GH 12333)
In [104]: s = pd.Series([1, 2, 3], index=[4, 5, 6])
In [105]: s
Out[105]:
4 1
5 2
6 3
Length: 3, dtype: int64
In [106]: s2 = pd.Series([1, 2, 3], index=list('abc'))
In [107]: s2
Out[107]:
a 1
b 2
c 3
Length: 3, dtype: int64
以前の動作
# this is label indexing
In [2]: s[5.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[2]: 2
# this is positional indexing
In [3]: s.iloc[1.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[3]: 2
# this is label indexing
In [4]: s.loc[5.0]
FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[4]: 2
# .ix would coerce 1.0 to the positional 1, and index
In [5]: s2.ix[1.0] = 10
FutureWarning: scalar indexers for index type Index should be integers and not floating point
In [6]: s2
Out[6]:
a 1
b 10
c 3
dtype: int64
新しい動作
iloc の場合、浮動小数点スカラによる取得と設定は常に例外を発生させます。
In [3]: s.iloc[2.0]
TypeError: cannot do label indexing on <class 'pandas.indexes.numeric.Int64Index'> with these indexers [2.0] of <type 'float'>
他のインデクサーは、取得と設定の両方で整数のような値に変換されます。.loc、.ix、および [] の FutureWarning は削除されました。
In [108]: s[5.0]
Out[108]: 2
In [109]: s.loc[5.0]
Out[109]: 2
そして設定
In [110]: s_copy = s.copy()
In [111]: s_copy[5.0] = 10
In [112]: s_copy
Out[112]:
4 1
5 10
6 3
Length: 3, dtype: int64
In [113]: s_copy = s.copy()
In [114]: s_copy.loc[5.0] = 10
In [115]: s_copy
Out[115]:
4 1
5 10
6 3
Length: 3, dtype: int64
.ix と浮動小数点インデクサによる位置指定設定は、以前のように位置で値を設定するのではなく、この値をインデックスに追加します。
In [3]: s2.ix[1.0] = 10
In [4]: s2
Out[4]:
a 1
b 2
c 3
1.0 10
dtype: int64
スライスも、非 Float64Index の場合、整数のような浮動小数点数を整数に強制します。
In [116]: s.loc[5.0:6]
Out[116]:
5 2
6 3
Length: 2, dtype: int64
整数に強制できない浮動小数点数の場合、ラベルベースの境界は除外されることに注意してください。
In [117]: s.loc[5.1:6]
Out[117]:
6 3
Length: 1, dtype: int64
Float64Index の浮動小数点インデックスは変更されていません。
In [118]: s = pd.Series([1, 2, 3], index=np.arange(3.))
In [119]: s[1.0]
Out[119]: 2
In [120]: s[1.0:2.5]
Out[120]:
1.0 2
2.0 3
Length: 2, dtype: int64
以前のバージョンの非推奨/変更の削除#
rolling_corr_pairwiseを.rolling().corr(pairwise=True)に置き換え、削除 (GH 4950)expanding_corr_pairwiseを.expanding().corr(pairwise=True)に置き換え、削除 (GH 4950)DataMatrixモジュールの削除。これは pandas 名前空間にはインポートされていませんでした (GH 12111)DataFrame.duplicated()およびDataFrame.drop_duplicates()でcolsキーワードをsubsetに置き換え、削除 (GH 6680)pd.io.sql名前空間内のread_frameとframe_query(両方ともpd.read_sqlのエイリアス) およびwrite_frame(to_sqlのエイリアス) 関数の削除 (0.14.0 から非推奨) (GH 6292)。.factorize()からorderキーワードの削除 (GH 6930)
パフォーマンス改善#
andrews_curvesのパフォーマンスが向上しました (GH 11534)巨大な
DatetimeIndex、PeriodIndex、TimedeltaIndexの演算パフォーマンスが向上し、NaTも含まれるようになりました (GH 10277)pandas.concatのパフォーマンスが向上しました (GH 11958)StataReaderのパフォーマンスが向上しました (GH 11591)NaTを含む日時 Series を使用したCategoricalsの構築パフォーマンスが向上しました (GH 12077)ISO 8601 日付解析のパフォーマンスが向上しました。区切り文字のない日付 (GH 11899)、先頭ゼロ (GH 11871)、タイムゾーンの前に空白がある日付 (GH 9714) で改善されました。
バグ修正#
DataFrame が空の場合の
GroupBy.sizeのバグ。 (GH 11699)複数の時間期間が要求された場合の
Period.end_timeのバグ (GH 11738)タイムゾーン対応日時を含む
.clipの回帰 (GH 11838).groupby(...).agg(...)にネストされた辞書を渡す際の一貫性のバグ (GH 9052)Timedeltaコンストラクタでユニコードを受け入れるようになりました (GH 11995)増分読み込み時の
StataReaderの値ラベル読み込みにおけるバグ (GH 12014)nパラメータが0の場合のベクトル化されたDateOffsetのバグ (GH 11370)numpy 1.11 との
NaT比較変更に関する互換性 (GH 12049)スレッドで
StringIOから読み込む際のread_csvのバグ (GH 11790)因子化と
Categoricalsを使用する際に、NaTを日時型における欠損値として扱わないバグ (GH 12077)Seriesの値がタイムゾーン対応であった場合の getitem のバグ (GH 12089)変数の一つが「name」であった場合の
Series.str.get_dummiesのバグ (GH 12180)タイムゾーン対応の NaT シリーズを連結する際の
pd.concatのバグ。 (GH 11693, GH 11755, GH 12217)バージョン <= 108 のファイルで
pd.read_stataのバグ (GH 12232)インデックスが
DatetimeIndexであり、非ゼロのナノ秒部分を含む場合のNano頻度を使用するSeries.resampleのバグ (GH 12037).nuniqueと疎なインデックスを使用するリサンプリングのバグ (GH 12352)いくつかのコンパイラ警告を削除しました (GH 12471)
Python 3.5 での
botoとの互換性問題を回避 (GH 11915)タイムゾーン付きの
TimestampまたはDatetimeIndexからNaTを減算する際のバグ (GH 11718)単一のタイムゾーン対応
TimestampのSeriesを減算する際のバグ (GH 12290)PY2 で互換性のあるイテレータを使用して
.next()をサポート (GH 12299)負の値を持つ
Timedelta.roundのバグ (GH 11690)CategoricalIndexに対する.locのバグにより、通常のIndexが生成される可能性があった (GH 11586)重複する列名が存在する場合の
DataFrame.infoのバグ (GH 11761)日時タイムゾーン対応オブジェクトの
.copyのバグ (GH 11794)Series.applyおよびSeries.mapでtimedelta64がボックス化されなかったバグ (GH 11349)タイムゾーン対応の
Seriesを使用したDataFrame.set_index()のバグ (GH 12358)DataFrameのサブクラスでAttributeErrorが伝播しなかったバグ (GH 11808)タイムゾーン対応データの groupby で、選択が
Timestampを返さないバグ (GH 11616)pd.read_clipboardおよびpd.to_clipboard関数が Unicode をサポートしないバグ。アップグレードによりpyperclipが v1.5.15 に更新されました (GH 9263)代入を含む
DataFrame.queryのバグ (GH 8664)from_msgpackのバグで、DataFrameにオブジェクト列がある場合、アンパックされたDataFrameの列に対して__contains__()が失敗しました。 (GH 11880)TimedeltaIndexを持つカテゴリカルデータに対する.resampleのバグ (GH 12169)スカラー日時を
DataFrameにブロードキャストする際にタイムゾーン情報が失われるバグ (GH 11682)タイムゾーンが混在する
TimestampからIndexを作成する際、UTC に強制変換されるバグ (GH 11488)to_numericが入力が1次元以上の場合に例外を発生させないバグ (GH 11776)非ゼロ分のタイムゾーンオフセット文字列を解析する際のバグ (GH 11708)
matplotlib 1.5+ で df.plot が棒グラフに誤った色を使用するバグ (GH 11614)
キーワード引数を使用する際の
groupbyplotメソッドのバグ (GH 11805)。DataFrame.duplicatedとdrop_duplicatesでkeep=Falseを設定すると誤った一致が発生するバグ (GH 11864)重複キーを持つ
.locの結果で、Indexの dtype が誤っている場合があるバグ (GH 11497)pd.rolling_medianのバグにより、十分なメモリがある場合でもメモリ割り当てに失敗した (GH 11696)DataFrame.styleのバグで、誤ったゼロが表示される (GH 12134)整数列が0から始まらない場合の
DataFrame.styleのバグ (GH 12125)特定のブラウザで
.style.barが適切にレンダリングされないバグ (GH 11678)Timedeltaとnumpy.arrayofTimedeltaの豊かな比較におけるバグで、無限再帰を引き起こした (GH 11835)DataFrame.roundが列インデックス名を削除するバグ (GH 11986)混合 dtype の
Dataframeで値を置き換える際のdf.replaceのバグ (GH 11698)新しい名前が指定されていない場合に、渡された
Indexの名前のコピーを妨げるIndexのバグ (GH 11193)空のシートが存在し、
sheetname=Noneの場合、read_excelが空でないシートを読み込めないバグ (GH 11711)read_excelが、parse_datesおよびdate_parserキーワードが指定された場合にNotImplementedエラーを発生させないバグ (GH 11544)read_sqlとpymysql接続でチャンクされたデータを返せないバグ (GH 11522).to_csvが、浮動小数点インデックスの書式設定パラメータdecimal、na_rep、float_formatを無視するバグ (GH 11553)Int64IndexとFloat64Indexでモジュロ演算子を使用できないバグ (GH 9244)lexsorted ではない MultiIndex の
MultiIndex.dropのバグ (GH 12078)空の
DataFrameをマスキングする際のDataFrameのバグ (GH 11859)列の数が提供されたシリーズの数と一致しない場合、
.plotがcolors入力を変更する可能性のあるバグ (GH 12039)。インデックスが
CustomBusinessDay頻度を持つ場合にSeries.plotが失敗するバグ (GH 7222)。sqlite フォールバックで
datetime.time値を.to_sqlする際のバグ (GH 8341)squeeze=Trueの場合に、1列のデータをread_excelが読み込めないバグ (GH 12157).groupbyのバグで、DataFrame に行が1つしかない場合に、誤った列に対してKeyErrorが発生しなかった (GH 11741)空のデータに対して dtype を指定した
.read_csvでエラーが発生するバグ (GH 12048).read_csvのバグで、'2E'のような文字列が有効な浮動小数点数として扱われた (GH 12237)デバッグシンボル付きで pandas をビルドする際のバグ (GH 12123)
DatetimeIndexのmillisecondプロパティを削除。これは常にValueErrorを発生させていた (GH 12019)。読み取り専用データを持つ
Seriesコンストラクタのバグ (GH 11502)pandas._testing.choice()を削除しました。代わりにnp.random.choice()を使用してください。 (GH 12386).locsetitemインデクサーのバグにより、TZ対応のDatetimeIndexが使用できなかった問題 (GH 12050).styleのインデックスとMultiIndexが表示されないバグ (GH 11655)to_msgpackとfrom_msgpackでNaTが正しくシリアライズまたはデシリアライズされなかったバグ (GH 12307)。非常に類似した値の丸め誤差による
.skewおよび.kurtのバグ (GH 11974)Timestampコンストラクタで、HHMMSSが「:」で区切られていない場合にマイクロ秒の精度が失われたバグ (GH 10041)buffer_rd_bytesで読み取りが失敗した場合にsrc->bufferが複数回解放される可能性があり、セグメンテーション違反を引き起こすバグ (GH 12098)crosstabで、重なり合わないインデックスを持つ引数がKeyErrorを返していたバグ (GH 10291)DataFrame.applyで、dtypeがnumpy dtypeではない場合に削減が防止されていなかったバグ (GH 12244)カテゴリカルシリーズをスカラ値で初期化する際のバグ。 (GH 12336)
.to_datetimeでutc=Trueを設定してUTCDatetimeIndexを指定する際のバグ (GH 11934)read_csvでCSVリーダーのバッファサイズを増やす際のバグ (GH 12494)重複する列名を持つ
DataFrameの列を設定する際のバグ (GH 12344)
貢献者#
このリリースには合計101人がパッチを提供しました。「+」が付いている人は初めてパッチを寄稿しました。
ARF +
Alex Alekseyev +
Andrew McPherson +
アンドリュー・ローゼンフェルド
アンディ・ヘイデン
Anthonios Partheniou
Anton I. Sipos
Ben +
Ben North +
Bran Yang +
Chris
Chris Carroux +
Christopher C. Aycock +
Christopher Scanlin +
Cody +
Da Wang +
Daniel Grady +
Dorozhko Anton +
Dr-Irv +
Erik M. Bray +
エヴァン・ライト
Francis T. O’Donovan +
Frank Cleary +
Gianluca Rossi
Graham Jeffries +
Guillaume Horel
Henry Hammond +
Isaac Schwabacher +
Jean-Mathieu Deschenes
ジェフ・リーバック
Joe Jevnik +
John Freeman +
John Fremlin +
Jonas Hoersch +
Joris Van den Bossche
Joris Vankerschaver
Justin Lecher
Justin Lin +
カ・ウォ・チェン
Keming Zhang +
カービー・シェデン
Kyle +
Marco Farrugia +
MasonGallo +
MattRijk +
Matthew Lurie +
Maximilian Roos
Mayank Asthana +
モルタダ・メヒヤル
Moussa Taifi +
Navreet Gill +
Nicolas Bonnotte
Paul Reiners +
Philip Gura +
ピエトロ・バティストン
RahulHP +
Randy Carnevale
Rinoc Johnson
Rishipuri +
Sangmin Park +
Scott E Lasley
Sereger13 +
Shannon Wang +
スキッパー・シーボールド
ティエリー・モワザン
トーマス・A・キャスウェル
Toby Dylan Hocking +
Tom Augspurger
Travis +
Trent Hauck
Tux1
Varun
Wes McKinney
Will Thompson +
Yoav Ram
Yoong Kang Lim +
ヨシキ・バスケス・バエザ
Young Joong Kim +
ヨンガン・キム
Yuval Langer +
alex argunov +
behzad nouri
boombard +
brian-pantano +
chromy +
daniel +
dgram0 +
gfyoung +
hack-c +
hcontrast +
jfoo +
kaustuv deolal +
llllllllll
ranarag +
ロックg
scls19fr
seales +
sinhrks
srib +
surveymedia.ca +
tworec +