0.19.0版(2016年10月2日)#
这是从0.18.1发布的一个主要版本,包括一些API更改、几个新功能、增强功能和性能改进,以及大量的错误修复。我们建议所有用户升级到此版本。
亮点包括:
merge_asof()
for asof-style time-series joining, see here.rolling()
is now time-series aware, see hereread_csv()
now supports parsingCategorical
data, see here一项功能
union_categorical()
已添加用于组合范畴词,请参见 herePeriodIndex
now has its ownperiod
dtype, and changed to be more consistent with otherIndex
classes. See here稀疏数据结构得到了增强的支持
int
和bool
数据类型,请参见 here比较运算与
Series
不再忽略索引,请参见 here 以获取API更改的概述。介绍实用程序函数的PANAS开发API,请参阅 here 。
不推荐使用
Panel4D
andPanelND
. We recommend to represent these types of n-dimensional data with the xarray package 。删除以前不推荐使用的模块
pandas.io.data
,pandas.io.wb
,pandas.tools.rplot
。
警告
Pandas>=0.19.0将不再在进口时静音,请参见 here 。
V0.19.0中的新功能
新功能#
功能 merge_asof
对于AS-OF风格的时间序列连接#
一项长期请求的功能已通过 merge_asof()
功能,支持时间序列的as of style连接 (GH1870 , GH13695 , GH13709 , GH13902 )。完整的文档是 here 。
这个 merge_asof()
执行asof合并,这类似于左联接,不同之处在于我们匹配最近的键而不是相等的键。
In [1]: left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]})
In [2]: right = pd.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]})
In [3]: left
Out[3]:
a left_val
0 1 a
1 5 b
2 10 c
[3 rows x 2 columns]
In [4]: right
Out[4]:
a right_val
0 1 1
1 2 2
2 3 3
3 6 6
4 7 7
[5 rows x 2 columns]
我们通常希望在可能的情况下完全匹配,否则使用最新的值。
In [5]: pd.merge_asof(left, right, on="a")
Out[5]:
a left_val right_val
0 1 a 1
1 5 b 3
2 10 c 7
[3 rows x 3 columns]
我们还可以只将行与先前的数据进行匹配,而不是完全匹配。
In [6]: pd.merge_asof(left, right, on="a", allow_exact_matches=False)
Out[6]:
a left_val right_val
0 1 a NaN
1 5 b 3.0
2 10 c 7.0
[3 rows x 3 columns]
在一个典型的时间序列示例中,我们有 trades
和 quotes
我们想要 asof-join
他们。这也说明了如何使用 by
参数在合并前对数据进行分组。
In [7]: trades = pd.DataFrame(
...: {
...: "time": pd.to_datetime(
...: [
...: "20160525 13:30:00.023",
...: "20160525 13:30:00.038",
...: "20160525 13:30:00.048",
...: "20160525 13:30:00.048",
...: "20160525 13:30:00.048",
...: ]
...: ),
...: "ticker": ["MSFT", "MSFT", "GOOG", "GOOG", "AAPL"],
...: "price": [51.95, 51.95, 720.77, 720.92, 98.00],
...: "quantity": [75, 155, 100, 100, 100],
...: },
...: columns=["time", "ticker", "price", "quantity"],
...: )
...:
In [8]: quotes = pd.DataFrame(
...: {
...: "time": pd.to_datetime(
...: [
...: "20160525 13:30:00.023",
...: "20160525 13:30:00.023",
...: "20160525 13:30:00.030",
...: "20160525 13:30:00.041",
...: "20160525 13:30:00.048",
...: "20160525 13:30:00.049",
...: "20160525 13:30:00.072",
...: "20160525 13:30:00.075",
...: ]
...: ),
...: "ticker": ["GOOG", "MSFT", "MSFT", "MSFT", "GOOG", "AAPL", "GOOG", "MSFT"],
...: "bid": [720.50, 51.95, 51.97, 51.99, 720.50, 97.99, 720.50, 52.01],
...: "ask": [720.93, 51.96, 51.98, 52.00, 720.93, 98.01, 720.88, 52.03],
...: },
...: columns=["time", "ticker", "bid", "ask"],
...: )
...:
In [9]: trades
Out[9]:
time ticker price quantity
0 2016-05-25 13:30:00.023 MSFT 51.95 75
1 2016-05-25 13:30:00.038 MSFT 51.95 155
2 2016-05-25 13:30:00.048 GOOG 720.77 100
3 2016-05-25 13:30:00.048 GOOG 720.92 100
4 2016-05-25 13:30:00.048 AAPL 98.00 100
[5 rows x 4 columns]
In [10]: quotes
Out[10]:
time ticker bid ask
0 2016-05-25 13:30:00.023 GOOG 720.50 720.93
1 2016-05-25 13:30:00.023 MSFT 51.95 51.96
2 2016-05-25 13:30:00.030 MSFT 51.97 51.98
3 2016-05-25 13:30:00.041 MSFT 51.99 52.00
4 2016-05-25 13:30:00.048 GOOG 720.50 720.93
5 2016-05-25 13:30:00.049 AAPL 97.99 98.01
6 2016-05-25 13:30:00.072 GOOG 720.50 720.88
7 2016-05-25 13:30:00.075 MSFT 52.01 52.03
[8 rows x 4 columns]
一个asof合并在 on
,通常是一个类似日期时间的字段,它是有序的,在本例中我们在 by
菲尔德。这类似于左-外联接,不同之处在于前向填充会自动采用最新的非NaN值。
In [11]: pd.merge_asof(trades, quotes, on="time", by="ticker")
Out[11]:
time ticker price quantity bid ask
0 2016-05-25 13:30:00.023 MSFT 51.95 75 51.95 51.96
1 2016-05-25 13:30:00.038 MSFT 51.95 155 51.97 51.98
2 2016-05-25 13:30:00.048 GOOG 720.77 100 720.50 720.93
3 2016-05-25 13:30:00.048 GOOG 720.92 100 720.50 720.93
4 2016-05-25 13:30:00.048 AAPL 98.00 100 NaN NaN
[5 rows x 6 columns]
这将返回一个合并的DataFrame,其中条目的顺序与原始的左侧传递的DataFrame相同 (trades
在本例中),具有 quotes
合并了。
方法 .rolling()
现在时间序列意识到了#
.rolling()
对象现在是时序感知的,并且可以接受 window
论据 (GH13327 , GH12995 )。请参阅完整文档 here 。
In [12]: dft = pd.DataFrame(
....: {"B": [0, 1, 2, np.nan, 4]},
....: index=pd.date_range("20130101 09:00:00", periods=5, freq="s"),
....: )
....:
In [13]: dft
Out[13]:
B
2013-01-01 09:00:00 0.0
2013-01-01 09:00:01 1.0
2013-01-01 09:00:02 2.0
2013-01-01 09:00:03 NaN
2013-01-01 09:00:04 4.0
[5 rows x 1 columns]
这是一个常规的频率索引。使用整型窗口参数可以沿着窗口频率滚动。
In [14]: dft.rolling(2).sum()
Out[14]:
B
2013-01-01 09:00:00 NaN
2013-01-01 09:00:01 1.0
2013-01-01 09:00:02 3.0
2013-01-01 09:00:03 NaN
2013-01-01 09:00:04 NaN
[5 rows x 1 columns]
In [15]: dft.rolling(2, min_periods=1).sum()
Out[15]:
B
2013-01-01 09:00:00 0.0
2013-01-01 09:00:01 1.0
2013-01-01 09:00:02 3.0
2013-01-01 09:00:03 2.0
2013-01-01 09:00:04 4.0
[5 rows x 1 columns]
通过指定偏移量,可以更直观地指定滚动频率。
In [16]: dft.rolling("2s").sum()
Out[16]:
B
2013-01-01 09:00:00 0.0
2013-01-01 09:00:01 1.0
2013-01-01 09:00:02 3.0
2013-01-01 09:00:03 2.0
2013-01-01 09:00:04 4.0
[5 rows x 1 columns]
使用非规则但仍是单调的索引,使用整数窗口滚动不会带来任何特殊计算。
In [17]: dft = pd.DataFrame(
....: {"B": [0, 1, 2, np.nan, 4]},
....: index=pd.Index(
....: [
....: pd.Timestamp("20130101 09:00:00"),
....: pd.Timestamp("20130101 09:00:02"),
....: pd.Timestamp("20130101 09:00:03"),
....: pd.Timestamp("20130101 09:00:05"),
....: pd.Timestamp("20130101 09:00:06"),
....: ],
....: name="foo",
....: ),
....: )
....:
In [18]: dft
Out[18]:
B
foo
2013-01-01 09:00:00 0.0
2013-01-01 09:00:02 1.0
2013-01-01 09:00:03 2.0
2013-01-01 09:00:05 NaN
2013-01-01 09:00:06 4.0
[5 rows x 1 columns]
In [19]: dft.rolling(2).sum()
Out[19]:
B
foo
2013-01-01 09:00:00 NaN
2013-01-01 09:00:02 1.0
2013-01-01 09:00:03 3.0
2013-01-01 09:00:05 NaN
2013-01-01 09:00:06 NaN
[5 rows x 1 columns]
使用时间规范为该稀疏数据生成可变窗口。
In [20]: dft.rolling("2s").sum()
Out[20]:
B
foo
2013-01-01 09:00:00 0.0
2013-01-01 09:00:02 1.0
2013-01-01 09:00:03 3.0
2013-01-01 09:00:05 NaN
2013-01-01 09:00:06 4.0
[5 rows x 1 columns]
此外,我们现在允许可选的 on
参数指定DataFrame中的列(而不是索引的默认列)。
In [21]: dft = dft.reset_index()
In [22]: dft
Out[22]:
foo B
0 2013-01-01 09:00:00 0.0
1 2013-01-01 09:00:02 1.0
2 2013-01-01 09:00:03 2.0
3 2013-01-01 09:00:05 NaN
4 2013-01-01 09:00:06 4.0
[5 rows x 2 columns]
In [23]: dft.rolling("2s", on="foo").sum()
Out[23]:
foo B
0 2013-01-01 09:00:00 0.0
1 2013-01-01 09:00:02 1.0
2 2013-01-01 09:00:03 3.0
3 2013-01-01 09:00:05 NaN
4 2013-01-01 09:00:06 4.0
[5 rows x 2 columns]
方法 read_csv
改进了对重复列名的支持#
Duplicate column names 现在支持 read_csv()
无论它们是在文件中还是作为 names
参数 (GH7160 , GH9424 )
In [24]: data = "0,1,2\n3,4,5"
In [25]: names = ["a", "b", "a"]
以前的行为 :
In [2]: pd.read_csv(StringIO(data), names=names)
Out[2]:
a b a
0 2 1 2
1 5 4 5
第一 a
列包含的数据与第二个 a
列,而它本应包含这些值 [0, 3]
。
新行为 :
In [26]: pd.read_csv(StringIO(data), names=names)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [26], in <cell line: 1>()
----> 1 pd.read_csv(StringIO(data), names=names)
File /usr/local/lib/python3.10/dist-packages/pandas-1.5.0.dev0+697.gf9762d8f52-py3.10-linux-x86_64.egg/pandas/util/_decorators.py:317, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
311 if len(args) > num_allow_args:
312 warnings.warn(
313 msg.format(arguments=arguments),
314 FutureWarning,
315 stacklevel=stacklevel,
316 )
--> 317 return func(*args, **kwargs)
File /usr/local/lib/python3.10/dist-packages/pandas-1.5.0.dev0+697.gf9762d8f52-py3.10-linux-x86_64.egg/pandas/io/parsers/readers.py:927, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
912 kwds_defaults = _refine_defaults_read(
913 dialect,
914 delimiter,
(...)
923 defaults={"delimiter": ","},
924 )
925 kwds.update(kwds_defaults)
--> 927 return _read(filepath_or_buffer, kwds)
File /usr/local/lib/python3.10/dist-packages/pandas-1.5.0.dev0+697.gf9762d8f52-py3.10-linux-x86_64.egg/pandas/io/parsers/readers.py:579, in _read(filepath_or_buffer, kwds)
576 nrows = kwds.get("nrows", None)
578 # Check for duplicates in names.
--> 579 _validate_names(kwds.get("names", None))
581 # Create the parser.
582 parser = TextFileReader(filepath_or_buffer, **kwds)
File /usr/local/lib/python3.10/dist-packages/pandas-1.5.0.dev0+697.gf9762d8f52-py3.10-linux-x86_64.egg/pandas/io/parsers/readers.py:541, in _validate_names(names)
539 if names is not None:
540 if len(names) != len(set(names)):
--> 541 raise ValueError("Duplicate names are not allowed.")
542 if not (
543 is_list_like(names, allow_sets=False) or isinstance(names, abc.KeysView)
544 ):
545 raise ValueError("Names should be an ordered collection.")
ValueError: Duplicate names are not allowed.
方法 read_csv
支持解析 Categorical
直接直接#
这个 read_csv()
函数现在支持分析 Categorical
列(指定为数据类型时) (GH10153 )。根据数据结构的不同,与转换为 Categorical
在解析之后。请参阅Io docs here 。
In [27]: data = """
....: col1,col2,col3
....: a,b,1
....: a,b,2
....: c,d,3
....: """
....:
In [28]: pd.read_csv(StringIO(data))
Out[28]:
col1 col2 col3
0 a b 1
1 a b 2
2 c d 3
[3 rows x 3 columns]
In [29]: pd.read_csv(StringIO(data)).dtypes
Out[29]:
col1 object
col2 object
col3 int64
Length: 3, dtype: object
In [30]: pd.read_csv(StringIO(data), dtype="category").dtypes
Out[30]:
col1 category
col2 category
col3 category
Length: 3, dtype: object
单个列可以被解析为 Categorical
使用DICT规范
In [31]: pd.read_csv(StringIO(data), dtype={"col1": "category"}).dtypes
Out[31]:
col1 category
col2 object
col3 int64
Length: 3, dtype: object
备注
生成的类别将始终被解析为字符串(对象数据类型)。如果类别是数值类别,则可以使用 to_numeric()
函数,或在适当的情况下,另一个转换器,如 to_datetime()
。
In [32]: df = pd.read_csv(StringIO(data), dtype="category")
In [33]: df.dtypes
Out[33]:
col1 category
col2 category
col3 category
Length: 3, dtype: object
In [34]: df["col3"]
Out[34]:
0 1
1 2
2 3
Name: col3, Length: 3, dtype: category
Categories (3, object): ['1', '2', '3']
In [35]: df["col3"].cat.categories = pd.to_numeric(df["col3"].cat.categories)
In [36]: df["col3"]
Out[36]:
0 1
1 2
2 3
Name: col3, Length: 3, dtype: category
Categories (3, int64): [1, 2, 3]
范畴级联#
A function
union_categoricals()
has been added for combining categoricals, see Unioning Categoricals (GH13361, GH13763, GH13846, GH14173)In [37]: from pandas.api.types import union_categoricals In [38]: a = pd.Categorical(["b", "c"]) In [39]: b = pd.Categorical(["a", "b"]) In [40]: union_categoricals([a, b]) Out[40]: ['b', 'c', 'a', 'b'] Categories (3, object): ['b', 'c', 'a']
concat
和append
现在可以合并category
具有不同的数据类型categories
作为object
数据类型 (GH13524 )In [41]: s1 = pd.Series(["a", "b"], dtype="category") In [42]: s2 = pd.Series(["b", "c"], dtype="category")
以前的行为 :
In [1]: pd.concat([s1, s2])
ValueError: incompatible categories in categorical concat
新行为 :
In [43]: pd.concat([s1, s2])
Out[43]:
0 a
1 b
0 b
1 c
Length: 4, dtype: object
半个月抵销#
Pandas获得了新的频率偏移量, SemiMonthEnd
(‘SM’)和 SemiMonthBegin
(‘短信’)。它们提供的日期偏移量(默认情况下)分别固定到每月15号和月底,以及15号和1号。 (GH1543 )
In [44]: from pandas.tseries.offsets import SemiMonthEnd, SemiMonthBegin
SemiMonthEnd :
In [45]: pd.Timestamp("2016-01-01") + SemiMonthEnd()
Out[45]: Timestamp('2016-01-15 00:00:00')
In [46]: pd.date_range("2015-01-01", freq="SM", periods=4)
Out[46]: DatetimeIndex(['2015-01-15', '2015-01-31', '2015-02-15', '2015-02-28'], dtype='datetime64[ns]', freq='SM-15')
SemiMonthBegin :
In [47]: pd.Timestamp("2016-01-01") + SemiMonthBegin()
Out[47]: Timestamp('2016-01-15 00:00:00')
In [48]: pd.date_range("2015-01-01", freq="SMS", periods=4)
Out[48]: DatetimeIndex(['2015-01-01', '2015-01-15', '2015-02-01', '2015-02-15'], dtype='datetime64[ns]', freq='SMS-15')
使用锚定后缀,您还可以指定要使用的月份日期,而不是15号。
In [49]: pd.date_range("2015-01-01", freq="SMS-16", periods=4)
Out[49]: DatetimeIndex(['2015-01-01', '2015-01-16', '2015-02-01', '2015-02-16'], dtype='datetime64[ns]', freq='SMS-16')
In [50]: pd.date_range("2015-01-01", freq="SM-14", periods=4)
Out[50]: DatetimeIndex(['2015-01-14', '2015-01-31', '2015-02-14', '2015-02-28'], dtype='datetime64[ns]', freq='SM-14')
新的索引方法#
以下方法和选项被添加到 Index
,以更符合 Series
和 DataFrame
原料药。
Index
现在支持 .where()
用于相同形状索引的函数 (GH13170 )
In [51]: idx = pd.Index(["a", "b", "c"])
In [52]: idx.where([True, False, True])
Out[52]: Index(['a', None, 'c'], dtype='object')
Index
现在支持 .dropna()
排除缺失值的步骤 (GH6194 )
In [53]: idx = pd.Index([1, 2, np.nan, 4])
In [54]: idx.dropna()
Out[54]: Float64Index([1.0, 2.0, 4.0], dtype='float64')
为 MultiIndex
默认情况下,如果缺少任何级别,则会丢弃这些值。指定 how='all'
仅丢弃缺少所有级别的值。
In [55]: midx = pd.MultiIndex.from_arrays([[1, 2, np.nan, 4], [1, 2, np.nan, np.nan]])
In [56]: midx
Out[56]:
MultiIndex([(1.0, 1.0),
(2.0, 2.0),
(nan, nan),
(4.0, nan)],
)
In [57]: midx.dropna()
Out[57]:
MultiIndex([(1, 1),
(2, 2)],
)
In [58]: midx.dropna(how="all")
Out[58]:
MultiIndex([(1, 1.0),
(2, 2.0),
(4, nan)],
)
Index
now supports .str.extractall()
which returns a DataFrame
, see the docs here (GH10008, GH13156)
In [59]: idx = pd.Index(["a1a2", "b1", "c1"])
In [60]: idx.str.extractall(r"[ab](?P<digit>\d)")
Out[60]:
digit
match
0 0 1
1 2
1 0 1
[3 rows x 1 columns]
Index.astype()
现在接受可选的布尔参数 copy
,它允许在满足dtype要求的情况下进行可选复制 (GH13209 )
Google BigQuery增强功能#
这个
read_gbq()
方法已经获得了dialect
argument to allow users to specify whether to use BigQuery's legacy SQL or BigQuery's standard SQL. See the docs 获取更多详细信息 (GH13615 )。
细粒度NumPy错误状态#
以前的Pandas版本在以下情况下会永久停止NumPy的ufunc错误处理 pandas
是进口的。Pandas这样做是为了让因对缺失数据使用NumPy UFunction而产生的警告保持沉默,这些数据通常表示为 NaN
不幸的是,这屏蔽了应用程序中非PANDA代码中出现的合法警告。从0.19.0开始,Pandas将使用 numpy.errstate
上下文管理器以更细粒度的方式使这些警告静默,仅在PANAS代码库中实际使用这些操作的位置附近。 (GH13109 , GH13145 )
升级Pandas后,你可能会看到 new RuntimeWarnings
being issued from your code. These are likely legitimate, and the underlying cause likely existed in the code when using previous versions of pandas that simply silenced the warning. Use numpy.errstate 围绕着这个问题的源头 RuntimeWarning
来控制这些情况的处理方式。
方法 get_dummies
现在返回整型数据类型#
这个 pd.get_dummies
函数现在将虚拟编码的列返回为小整数,而不是浮点数 (GH8725 )。这应该会改善内存占用量。
以前的行为 :
In [1]: pd.get_dummies(['a', 'b', 'a', 'c']).dtypes
Out[1]:
a float64
b float64
c float64
dtype: object
新行为 :
In [61]: pd.get_dummies(["a", "b", "a", "c"]).dtypes
Out[61]:
a uint8
b uint8
c uint8
Length: 3, dtype: object
将值向下转换为可能的最小数据类型 to_numeric
#
pd.to_numeric()
现在接受 downcast
参数,该参数在可能的情况下将数据向下转换为最小的指定数值数据类型 (GH13352 )
In [62]: s = ["1", 2, 3]
In [63]: pd.to_numeric(s, downcast="unsigned")
Out[63]: array([1, 2, 3], dtype=uint8)
In [64]: pd.to_numeric(s, downcast="integer")
Out[64]: array([1, 2, 3], dtype=int8)
Pandas开发API#
作为未来使PandasAPI更统一和更容易获得的一部分,我们创建了Pandas的标准子包, pandas.api
来保存公共API。我们首先在 pandas.api.types
。更多的子包和官方批准的API将在未来的Pandas版本中发布 (GH13147 , GH13634 )
以下内容现已包含在此接口中:
In [65]: import pprint
In [66]: from pandas.api import types
In [67]: funcs = [f for f in dir(types) if not f.startswith("_")]
In [68]: pprint.pprint(funcs)
['CategoricalDtype',
'DatetimeTZDtype',
'IntervalDtype',
'PeriodDtype',
'infer_dtype',
'is_array_like',
'is_bool',
'is_bool_dtype',
'is_categorical',
'is_categorical_dtype',
'is_complex',
'is_complex_dtype',
'is_datetime64_any_dtype',
'is_datetime64_dtype',
'is_datetime64_ns_dtype',
'is_datetime64tz_dtype',
'is_dict_like',
'is_dtype_equal',
'is_extension_array_dtype',
'is_extension_type',
'is_file_like',
'is_float',
'is_float_dtype',
'is_hashable',
'is_int64_dtype',
'is_integer',
'is_integer_dtype',
'is_interval',
'is_interval_dtype',
'is_iterator',
'is_list_like',
'is_named_tuple',
'is_number',
'is_numeric_dtype',
'is_object_dtype',
'is_period_dtype',
'is_re',
'is_re_compilable',
'is_scalar',
'is_signed_integer_dtype',
'is_sparse',
'is_string_dtype',
'is_timedelta64_dtype',
'is_timedelta64_ns_dtype',
'is_unsigned_integer_dtype',
'pandas_dtype',
'union_categoricals']
备注
Calling these functions from the internal module pandas.core.common
will now show a DeprecationWarning
(GH13990)
其他增强功能#
Timestamp
can now accept positional and keyword parameters similar todatetime.datetime()
(GH10758, GH11630)In [69]: pd.Timestamp(2012, 1, 1) Out[69]: Timestamp('2012-01-01 00:00:00') In [70]: pd.Timestamp(year=2012, month=1, day=1, hour=8, minute=30) Out[70]: Timestamp('2012-01-01 08:30:00')
这个
.resample()
函数现在接受一个on=
或level=
用于对类似日期时间的列进行重采样的参数或MultiIndex
级别 (GH13500 )In [71]: df = pd.DataFrame( ....: {"date": pd.date_range("2015-01-01", freq="W", periods=5), "a": np.arange(5)}, ....: index=pd.MultiIndex.from_arrays( ....: [[1, 2, 3, 4, 5], pd.date_range("2015-01-01", freq="W", periods=5)], ....: names=["v", "d"], ....: ), ....: ) ....: In [72]: df Out[72]: date a v d 1 2015-01-04 2015-01-04 0 2 2015-01-11 2015-01-11 1 3 2015-01-18 2015-01-18 2 4 2015-01-25 2015-01-25 3 5 2015-02-01 2015-02-01 4 [5 rows x 2 columns] In [73]: df.resample("M", on="date").sum() Out[73]: a date 2015-01-31 6 2015-02-28 4 [2 rows x 1 columns] In [74]: df.resample("M", level="d").sum() Out[74]: a d 2015-01-31 6 2015-02-28 4 [2 rows x 1 columns]
这个
.get_credentials()
method ofGbqConnector
can now first try to fetch the application default credentials 。有关详细信息,请参阅文档 (GH13577 )。The
.tz_localize()
method ofDatetimeIndex
andTimestamp
has gained theerrors
keyword, so you can potentially coerce nonexistent timestamps toNaT
. The default behavior remains to raising aNonExistentTimeError
(GH13057).to_hdf/read_hdf()
现在接受路径对象(例如pathlib.Path
,py.path.local
)作为文件路径 (GH11773 )The
pd.read_csv()
withengine='python'
has gained support for thedecimal
(GH12933),na_filter
(GH13321) and thememory_map
option (GH13381).与PythonAPI一致,
pd.read_csv()
现在将解读+inf
作为正无穷大 (GH13274 )这个
pd.read_html()
已经获得了对na_values
,converters
,keep_default_na
选项 (GH13461 )Categorical.astype()
现在接受可选的布尔参数copy
,在数据类型为绝对类型时有效 (GH13209 )DataFrame
已经获得了.asof()
方法根据选定的子集返回最后一个非NaN值 (GH13358 )这个
DataFrame
构造函数现在将尊重键顺序,如果OrderedDict
对象被传入 (GH13304 )pd.read_html()
已经获得了对decimal
选项 (GH12907 )Series
has gained the properties.is_monotonic
,.is_monotonic_increasing
,.is_monotonic_decreasing
, similar toIndex
(GH13336)DataFrame.to_sql()
现在允许将单个值作为所有列的SQL类型 (GH11886 )。Series.append
现在支持ignore_index
选项 (GH13677 ).to_stata()
和StataWriter
现在可以使用字典将列名转换为标签,将变量标签写入Stata DTA文件 (GH13535 , GH13536 ).to_stata()
andStataWriter
will automatically convertdatetime64[ns]
columns to Stata format%tc
, rather than raising aValueError
(GH12259)read_stata()
andStataReader
raise with a more explicit error message when reading Stata files with repeated value labels whenconvert_categoricals=True
(GH13923)DataFrame.style
现在将呈现稀疏多索引 (GH11655 )DataFrame.style
现在将显示列级名称(例如DataFrame.columns.names
) (GH13775 )DataFrame
has gained support to re-order the columns based on the values in a row usingdf.sort_values(by='...', axis=1)
(GH10806)In [75]: df = pd.DataFrame({"A": [2, 7], "B": [3, 5], "C": [4, 8]}, index=["row1", "row2"]) In [76]: df Out[76]: A B C row1 2 3 4 row2 7 5 8 [2 rows x 3 columns] In [77]: df.sort_values(by="row2", axis=1) Out[77]: B A C row1 3 2 4 row2 5 7 8 [2 rows x 3 columns]
to_html()
现在有一个border
参数控制洞口中的值<table>
标签。缺省值为html.border
这也会影响笔记本的HTMLepr,但由于Jupyter的CSS包含一个边框宽度属性,因此视觉效果是相同的。 (GH11563 )。加薪
ImportError
在SQL函数中,当sqlalchemy
未安装,并且使用了连接字符串 (GH11920 )。与matplotlib 2.0兼容。较老版本的Pandas也应该支持matplotlib 2.0 (GH13333 )
Timestamp
,Period
,DatetimeIndex
,PeriodIndex
和.dt
访问者已获得.is_leap_year
属性检查日期是否属于闰年。 (GH13727 )astype()
现在将接受列名到数据类型映射的字典作为dtype
论点。 (GH12086 )The
pd.read_json
andDataFrame.to_json
has gained support for reading and writing json lines withlines
option see Line delimited json (GH9180)read_excel()
现在支持TRUE_VALUES和FALSE_VALUES关键字参数 (GH13347 )groupby()
现在将接受标量和单元素列表,以指定level
在非``多索引``石斑鱼上。 (GH13907 )Excel日期列中的不可转换日期将返回而不进行转换,并且该列将
object
数据类型,而不是引发异常 (GH10001 )。pd.Timedelta(None)
is now accepted and will returnNaT
, mirroringpd.Timestamp
(GH13687)pd.read_stata()
现在可以处理一些格式111的文件,这些文件是在生成Stata DTA文件时由SAS生成的 (GH11526 )Series
和Index
现在支持divmod
它将返回序列或索引的元组。就广播规则而言,它的行为类似于标准二元运算符 (GH14208 )。
API更改#
Series.tolist()
现在将返回Python类型#
Series.tolist()
现在将在输出中返回Python类型,模仿NumPy .tolist()
行为 (GH10904 )
In [78]: s = pd.Series([1, 2, 3])
以前的行为 :
In [7]: type(s.tolist()[0])
Out[7]:
<class 'numpy.int64'>
新行为 :
In [79]: type(s.tolist()[0])
Out[79]: int
Series
不同索引的运算符#
Following Series
operators have been changed to make all operators consistent,
including DataFrame
(GH1134, GH4581, GH13538)
Series
比较运算符现在引发ValueError
什么时候index
是不同的。Series
逻辑运算符将两者对齐index
左右手边的。
警告
直到0.18.1,比较 Series
使用相同的长度,即使 .index
不同(结果忽略 .index
)。从0.19.0开始,这将引发 ValueError
要更严格一些。本节还介绍了如何使用灵活的比较方法保留以前的行为或对齐不同的索引,例如 .eq
。
结果, Series
和 DataFrame
操作符的行为如下:
算术运算符#
算术运算符将两者对齐 index
(无更改)。
In [80]: s1 = pd.Series([1, 2, 3], index=list("ABC"))
In [81]: s2 = pd.Series([2, 2, 2], index=list("ABD"))
In [82]: s1 + s2
Out[82]:
A 3.0
B 4.0
C NaN
D NaN
Length: 4, dtype: float64
In [83]: df1 = pd.DataFrame([1, 2, 3], index=list("ABC"))
In [84]: df2 = pd.DataFrame([2, 2, 2], index=list("ABD"))
In [85]: df1 + df2
Out[85]:
0
A 3.0
B 4.0
C NaN
D NaN
[4 rows x 1 columns]
比较运算符#
比较运算符引发 ValueError
什么时候 .index
是不同的。
Previous behavior (Series
):
Series
比较的值,忽略 .index
只要两者具有相同的长度:
In [1]: s1 == s2
Out[1]:
A False
B True
C False
dtype: bool
New behavior (Series
):
In [2]: s1 == s2
Out[2]:
ValueError: Can only compare identically-labeled Series objects
备注
要获得与以前版本相同的结果(根据位置比较值,忽略 .index
),将两者进行比较 .values
。
In [86]: s1.values == s2.values
Out[86]: array([False, True, False])
如果你想比较 Series
调整ITS .index
,请参阅下面的灵活比较方法部分:
In [87]: s1.eq(s2)
Out[87]:
A False
B True
C False
D False
Length: 4, dtype: bool
Current behavior (DataFrame
, no change):
In [3]: df1 == df2
Out[3]:
ValueError: Can only compare identically-labeled DataFrame objects
逻辑运算符#
逻辑运算符将两者对齐 .index
左右手边的。
Previous behavior (Series
), only left hand side index
was kept:
In [4]: s1 = pd.Series([True, False, True], index=list('ABC'))
In [5]: s2 = pd.Series([True, True, True], index=list('ABD'))
In [6]: s1 & s2
Out[6]:
A True
B False
C False
dtype: bool
New behavior (Series
):
In [88]: s1 = pd.Series([True, False, True], index=list("ABC"))
In [89]: s2 = pd.Series([True, True, True], index=list("ABD"))
In [90]: s1 & s2
Out[90]:
A True
B False
C False
D False
Length: 4, dtype: bool
备注
Series
逻辑运算符填充 NaN
结果为 False
。
备注
要获得与以前版本相同的结果(仅基于左侧索引比较值),您可以使用 reindex_like
:
In [91]: s1 & s2.reindex_like(s1)
Out[91]:
A True
B False
C False
Length: 3, dtype: bool
Current behavior (DataFrame
, no change):
In [92]: df1 = pd.DataFrame([True, False, True], index=list("ABC"))
In [93]: df2 = pd.DataFrame([True, True, True], index=list("ABD"))
In [94]: df1 & df2
Out[94]:
0
A True
B False
C False
D False
[4 rows x 1 columns]
灵活的比较方法#
Series
灵活的比较方法,如 eq
, ne
, le
, lt
, ge
和 gt
现在将两者对齐 index
。如果要比较两个运算符 Series
它有不同的 index
。
In [95]: s1 = pd.Series([1, 2, 3], index=["a", "b", "c"])
In [96]: s2 = pd.Series([2, 2, 2], index=["b", "c", "d"])
In [97]: s1.eq(s2)
Out[97]:
a False
b True
c False
d False
Length: 4, dtype: bool
In [98]: s1.ge(s2)
Out[98]:
a False
b True
c True
d False
Length: 4, dtype: bool
以前,这与比较运算符的工作方式相同(见上文)。
Series
在分配时键入升级#
A Series
现在将正确地将其用于赋值的数据类型升级为当前的数据类型 (GH13234 )
In [99]: s = pd.Series()
以前的行为 :
In [2]: s["a"] = pd.Timestamp("2016-01-01")
In [3]: s["b"] = 3.0
TypeError: invalid type promotion
新行为 :
In [100]: s["a"] = pd.Timestamp("2016-01-01")
In [101]: s["b"] = 3.0
In [102]: s
Out[102]:
a 2016-01-01 00:00:00
b 3.0
Length: 2, dtype: object
In [103]: s.dtype
Out[103]: dtype('O')
功能 .to_datetime()
变化#
以前的If .to_datetime()
遇到了混合的整数/浮点数和字符串,但没有 errors='coerce'
它会将所有内容转换为 NaT
。
以前的行为 :
In [2]: pd.to_datetime([1, 'foo'], errors='coerce')
Out[2]: DatetimeIndex(['NaT', 'NaT'], dtype='datetime64[ns]', freq=None)
当前行为 :
现在将使用默认单位转换整数/浮点数 ns
。
In [104]: pd.to_datetime([1, "foo"], errors="coerce")
Out[104]: DatetimeIndex(['1970-01-01 00:00:00.000000001', 'NaT'], dtype='datetime64[ns]', freq=None)
与以下相关的错误修复 .to_datetime()
:
Bug in
pd.to_datetime()
when passing integers or floats, and nounit
anderrors='coerce'
(GH13180).窃听
pd.to_datetime()
在传递无效数据类型(例如bool)时;现在将遵守errors
关键字 (GH13176 )窃听
pd.to_datetime()
它溢出了int8
,以及int16
数据类型 (GH13451 )Bug in
pd.to_datetime()
raiseAttributeError
withNaN
and the other string is not valid whenerrors='ignore'
(GH12424)窃听
pd.to_datetime()
在以下情况下未正确投射浮点数unit
被指定,导致截断的日期时间 (GH13834 )
正在合并更改#
合并现在将保留连接键的数据类型 (GH8596 )
In [105]: df1 = pd.DataFrame({"key": [1], "v1": [10]})
In [106]: df1
Out[106]:
key v1
0 1 10
[1 rows x 2 columns]
In [107]: df2 = pd.DataFrame({"key": [1, 2], "v1": [20, 30]})
In [108]: df2
Out[108]:
key v1
0 1 20
1 2 30
[2 rows x 2 columns]
以前的行为 :
In [5]: pd.merge(df1, df2, how='outer')
Out[5]:
key v1
0 1.0 10.0
1 1.0 20.0
2 2.0 30.0
In [6]: pd.merge(df1, df2, how='outer').dtypes
Out[6]:
key float64
v1 float64
dtype: object
新行为 :
我们能够保留连接密钥
In [109]: pd.merge(df1, df2, how="outer")
Out[109]:
key v1
0 1 10
1 1 20
2 2 30
[3 rows x 2 columns]
In [110]: pd.merge(df1, df2, how="outer").dtypes
Out[110]:
key int64
v1 int64
Length: 2, dtype: object
当然,如果引入了缺少的值,则结果数据类型将被向上转换,这与以前的没有变化。
In [111]: pd.merge(df1, df2, how="outer", on="key")
Out[111]:
key v1_x v1_y
0 1 10.0 20
1 2 NaN 30
[2 rows x 3 columns]
In [112]: pd.merge(df1, df2, how="outer", on="key").dtypes
Out[112]:
key int64
v1_x float64
v1_y int64
Length: 3, dtype: object
方法 .describe()
变化#
对象的索引中的百分位标识符。 .describe()
输出现在将四舍五入到使它们保持不同的最低精度 (GH13104 )
In [113]: s = pd.Series([0, 1, 2, 3, 4])
In [114]: df = pd.DataFrame([0, 1, 2, 3, 4])
以前的行为 :
百分位数最多四舍五入到小数点后一位,这可能会导致 ValueError
如果百分位数重复,则为数据帧。
In [3]: s.describe(percentiles=[0.0001, 0.0005, 0.001, 0.999, 0.9995, 0.9999])
Out[3]:
count 5.000000
mean 2.000000
std 1.581139
min 0.000000
0.0% 0.000400
0.1% 0.002000
0.1% 0.004000
50% 2.000000
99.9% 3.996000
100.0% 3.998000
100.0% 3.999600
max 4.000000
dtype: float64
In [4]: df.describe(percentiles=[0.0001, 0.0005, 0.001, 0.999, 0.9995, 0.9999])
Out[4]:
...
ValueError: cannot reindex from a duplicate axis
新行为 :
In [115]: s.describe(percentiles=[0.0001, 0.0005, 0.001, 0.999, 0.9995, 0.9999])
Out[115]:
count 5.000000
mean 2.000000
std 1.581139
min 0.000000
0.01% 0.000400
0.05% 0.002000
0.1% 0.004000
50% 2.000000
99.9% 3.996000
99.95% 3.998000
99.99% 3.999600
max 4.000000
Length: 12, dtype: float64
In [116]: df.describe(percentiles=[0.0001, 0.0005, 0.001, 0.999, 0.9995, 0.9999])
Out[116]:
0
count 5.000000
mean 2.000000
std 1.581139
min 0.000000
0.01% 0.000400
0.05% 0.002000
0.1% 0.004000
50% 2.000000
99.9% 3.996000
99.95% 3.998000
99.99% 3.999600
max 4.000000
[12 rows x 1 columns]
此外:
传球复制
percentiles
现在将引发一个ValueError
。Bug in
.describe()
on a DataFrame with a mixed-dtype column index, which would previously raise aTypeError
(GH13288)
Period
变化#
这个 PeriodIndex
现在有了 period
数据类型#
PeriodIndex
now has its own period
dtype. The period
dtype is a
pandas extension dtype like category
or the timezone aware dtype (datetime64[ns, tz]
) (GH13941).
As a consequence of this change, PeriodIndex
no longer has an integer dtype:
以前的行为 :
In [1]: pi = pd.PeriodIndex(['2016-08-01'], freq='D')
In [2]: pi
Out[2]: PeriodIndex(['2016-08-01'], dtype='int64', freq='D')
In [3]: pd.api.types.is_integer_dtype(pi)
Out[3]: True
In [4]: pi.dtype
Out[4]: dtype('int64')
新行为 :
In [117]: pi = pd.PeriodIndex(["2016-08-01"], freq="D")
In [118]: pi
Out[118]: PeriodIndex(['2016-08-01'], dtype='period[D]')
In [119]: pd.api.types.is_integer_dtype(pi)
Out[119]: False
In [120]: pd.api.types.is_period_dtype(pi)
Out[120]: True
In [121]: pi.dtype
Out[121]: period[D]
In [122]: type(pi.dtype)
Out[122]: pandas.core.dtypes.dtypes.PeriodDtype
Period('NaT')
now returns pd.NaT
#
在此之前, Period
有自己的 Period('NaT')
不同于的表示 pd.NaT
。现在 Period('NaT')
已更改为返回 pd.NaT
。 (GH12759 , GH13582 )
以前的行为 :
In [5]: pd.Period('NaT', freq='D')
Out[5]: Period('NaT', 'D')
新行为 :
这些结果导致 pd.NaT
如果不提供 freq
选项。
In [123]: pd.Period("NaT")
Out[123]: NaT
In [124]: pd.Period(None)
Out[124]: NaT
与…相容 Period
加法和减法 pd.NaT
现在支持使用 int
。此前,它提出了 ValueError
。
以前的行为 :
In [5]: pd.NaT + 1
...
ValueError: Cannot add integral value to Timestamp without freq.
新行为 :
In [125]: pd.NaT + 1
Out[125]: NaT
In [126]: pd.NaT - 1
Out[126]: NaT
PeriodIndex.values
现在返回数组 Period
对象#
.values
被更改为返回 Period
对象,而不是整数数组 (GH13988 )。
以前的行为 :
In [6]: pi = pd.PeriodIndex(['2011-01', '2011-02'], freq='M')
In [7]: pi.values
Out[7]: array([492, 493])
新行为 :
In [127]: pi = pd.PeriodIndex(["2011-01", "2011-02"], freq="M")
In [128]: pi.values
Out[128]: array([Period('2011-01', 'M'), Period('2011-02', 'M')], dtype=object)
索引 +
/ -
不再用于集合运算#
基本Index类型和DatetimeIndex(不是数字索引类型)的加法和减法以前执行了集合运算(集合、并集和差)。此行为已从0.15.0开始弃用(支持使用特定的 .union()
和 .difference()
方法),现在已禁用。如果可能的话, +
和 -
现在用于逐个元素的操作,例如连接字符串或减去日期时间 (GH8227 , GH14127 )。
以前的行为:
In [1]: pd.Index(['a', 'b']) + pd.Index(['a', 'c'])
FutureWarning: using '+' to provide set union with Indexes is deprecated, use '|' or .union()
Out[1]: Index(['a', 'b', 'c'], dtype='object')
新行为 :相同的操作现在将执行元素相加:
In [129]: pd.Index(["a", "b"]) + pd.Index(["a", "c"])
Out[129]: Index(['aa', 'bc'], dtype='object')
请注意,数字索引对象已经执行了元素级操作。例如,将两个整数索引相加的行为不变。基地 Index
现在与这一行为一致。
In [130]: pd.Index([1, 2, 3]) + pd.Index([2, 3, 4])
Out[130]: Int64Index([3, 5, 7], dtype='int64')
此外,由于此更改,现在可以将两个DatetimeIndex对象相减,从而得到TimedeltaIndex:
以前的行为 :
In [1]: (pd.DatetimeIndex(['2016-01-01', '2016-01-02'])
...: - pd.DatetimeIndex(['2016-01-02', '2016-01-03']))
FutureWarning: using '-' to provide set differences with datetimelike Indexes is deprecated, use .difference()
Out[1]: DatetimeIndex(['2016-01-01'], dtype='datetime64[ns]', freq=None)
新行为 :
In [131]: (
.....: pd.DatetimeIndex(["2016-01-01", "2016-01-02"])
.....: - pd.DatetimeIndex(["2016-01-02", "2016-01-03"])
.....: )
.....:
Out[131]: TimedeltaIndex(['-1 days', '-1 days'], dtype='timedelta64[ns]', freq=None)
Index.difference
和 .symmetric_difference
变化#
Index.difference
和 Index.symmetric_difference
现在会更始终如一地 NaN
值与任何其他值一样。 (GH13514 )
In [132]: idx1 = pd.Index([1, 2, 3, np.nan])
In [133]: idx2 = pd.Index([0, 1, np.nan])
以前的行为 :
In [3]: idx1.difference(idx2)
Out[3]: Float64Index([nan, 2.0, 3.0], dtype='float64')
In [4]: idx1.symmetric_difference(idx2)
Out[4]: Float64Index([0.0, nan, 2.0, 3.0], dtype='float64')
新行为 :
In [134]: idx1.difference(idx2)
Out[134]: Float64Index([2.0, 3.0], dtype='float64')
In [135]: idx1.symmetric_difference(idx2)
Out[135]: Float64Index([0.0, 2.0, 3.0], dtype='float64')
Index.unique
consistently returns Index
#
Index.unique()
现在将唯一值作为 Index
属于适当的 dtype
。 (GH13395 )。此前,大多数 Index
返回的类 np.ndarray
,以及 DatetimeIndex
, TimedeltaIndex
和 PeriodIndex
退货 Index
以保留像时区这样的元数据。
以前的行为 :
In [1]: pd.Index([1, 2, 3]).unique()
Out[1]: array([1, 2, 3])
In [2]: pd.DatetimeIndex(['2011-01-01', '2011-01-02',
...: '2011-01-03'], tz='Asia/Tokyo').unique()
Out[2]:
DatetimeIndex(['2011-01-01 00:00:00+09:00', '2011-01-02 00:00:00+09:00',
'2011-01-03 00:00:00+09:00'],
dtype='datetime64[ns, Asia/Tokyo]', freq=None)
新行为 :
In [136]: pd.Index([1, 2, 3]).unique()
Out[136]: Int64Index([1, 2, 3], dtype='int64')
In [137]: pd.DatetimeIndex(
.....: ["2011-01-01", "2011-01-02", "2011-01-03"], tz="Asia/Tokyo"
.....: ).unique()
.....:
Out[137]:
DatetimeIndex(['2011-01-01 00:00:00+09:00', '2011-01-02 00:00:00+09:00',
'2011-01-03 00:00:00+09:00'],
dtype='datetime64[ns, Asia/Tokyo]', freq=None)
MultiIndex
构造函数, groupby
和 set_index
保留分类数据类型#
MultiIndex.from_arrays
和 MultiIndex.from_product
中将保留绝对数据类型。 MultiIndex
级别 (GH13743 , GH13854 )。
In [138]: cat = pd.Categorical(["a", "b"], categories=list("bac"))
In [139]: lvl1 = ["foo", "bar"]
In [140]: midx = pd.MultiIndex.from_arrays([cat, lvl1])
In [141]: midx
Out[141]:
MultiIndex([('a', 'foo'),
('b', 'bar')],
)
以前的行为 :
In [4]: midx.levels[0]
Out[4]: Index(['b', 'a', 'c'], dtype='object')
In [5]: midx.get_level_values[0]
Out[5]: Index(['a', 'b'], dtype='object')
新行为 :单个级别现在是一个 CategoricalIndex
:
In [142]: midx.levels[0]
Out[142]: CategoricalIndex(['b', 'a', 'c'], categories=['b', 'a', 'c'], ordered=False, dtype='category')
In [143]: midx.get_level_values(0)
Out[143]: CategoricalIndex(['a', 'b'], categories=['b', 'a', 'c'], ordered=False, dtype='category')
一个类似的变化已经被做了 MultiIndex.from_product
。因此, groupby
和 set_index
还要在索引中保留分类数据类型
In [144]: df = pd.DataFrame({"A": [0, 1], "B": [10, 11], "C": cat})
In [145]: df_grouped = df.groupby(by=["A", "C"]).first()
In [146]: df_set_idx = df.set_index(["A", "C"])
以前的行为 :
In [11]: df_grouped.index.levels[1]
Out[11]: Index(['b', 'a', 'c'], dtype='object', name='C')
In [12]: df_grouped.reset_index().dtypes
Out[12]:
A int64
C object
B float64
dtype: object
In [13]: df_set_idx.index.levels[1]
Out[13]: Index(['b', 'a', 'c'], dtype='object', name='C')
In [14]: df_set_idx.reset_index().dtypes
Out[14]:
A int64
C object
B int64
dtype: object
新行为 :
In [147]: df_grouped.index.levels[1]
Out[147]: CategoricalIndex(['b', 'a', 'c'], categories=['b', 'a', 'c'], ordered=False, dtype='category', name='C')
In [148]: df_grouped.reset_index().dtypes
Out[148]:
A int64
C category
B float64
Length: 3, dtype: object
In [149]: df_set_idx.index.levels[1]
Out[149]: CategoricalIndex(['b', 'a', 'c'], categories=['b', 'a', 'c'], ordered=False, dtype='category', name='C')
In [150]: df_set_idx.reset_index().dtypes
Out[150]:
A int64
C category
B int64
Length: 3, dtype: object
功能 read_csv
将逐步枚举块#
什么时候 read_csv()
用来调用 chunksize=n
在没有指定索引的情况下,每个块过去都有一个独立生成的索引 0
至 n-1
。现在,他们被赋予了一个递进索引,从 0
对于第一个块,来自 n
用于第二个,依此类推,以便在串联时它们与调用 read_csv()
如果没有 chunksize=
论据 (GH12185 )。
In [151]: data = "A,B\n0,1\n2,3\n4,5\n6,7"
以前的行为 :
In [2]: pd.concat(pd.read_csv(StringIO(data), chunksize=2))
Out[2]:
A B
0 0 1
1 2 3
0 4 5
1 6 7
新行为 :
In [152]: pd.concat(pd.read_csv(StringIO(data), chunksize=2))
Out[152]:
A B
0 0 1
1 2 3
2 4 5
3 6 7
[4 rows x 2 columns]
稀疏变化#
这些更改允许Pandas处理具有更多数据类型的稀疏数据,并使工作人员获得更流畅的数据处理体验。
类型 int64
和 bool
支持增强功能#
Sparse data structures now gained enhanced support of int64
and bool
dtype
(GH667, GH13849).
以前,稀疏数据是 float64
默认情况下,即使所有输入都是 int
或 bool
数据类型。你必须指定 dtype
使用显式创建稀疏数据 int64
数据类型。另外, fill_value
必须显式指定,因为缺省值为 np.nan
它不会出现在 int64
或 bool
数据。
In [1]: pd.SparseArray([1, 2, 0, 0])
Out[1]:
[1.0, 2.0, 0.0, 0.0]
Fill: nan
IntIndex
Indices: array([0, 1, 2, 3], dtype=int32)
# specifying int64 dtype, but all values are stored in sp_values because
# fill_value default is np.nan
In [2]: pd.SparseArray([1, 2, 0, 0], dtype=np.int64)
Out[2]:
[1, 2, 0, 0]
Fill: nan
IntIndex
Indices: array([0, 1, 2, 3], dtype=int32)
In [3]: pd.SparseArray([1, 2, 0, 0], dtype=np.int64, fill_value=0)
Out[3]:
[1, 2, 0, 0]
Fill: 0
IntIndex
Indices: array([0, 1], dtype=int32)
从v0.19.0开始,稀疏数据保留输入数据类型,并使用更合适的 fill_value
默认值 (0
为 int64
Dtype、 False
为 bool
Dtype)。
In [153]: pd.SparseArray([1, 2, 0, 0], dtype=np.int64)
Out[153]:
[1, 2, 0, 0]
Fill: 0
IntIndex
Indices: array([0, 1], dtype=int32)
In [154]: pd.SparseArray([True, False, False, False])
Out[154]:
[True, False, False, False]
Fill: False
IntIndex
Indices: array([0], dtype=int32)
请参阅 docs 了解更多详细信息。
运算符现在保留数据类型#
稀疏数据结构现在可以保留
dtype
算术运算后 (GH13848 )
s = pd.SparseSeries([0, 2, 0, 1], fill_value=0, dtype=np.int64)
s.dtype
s + 1
Sparse data structure now support
astype
to convert internaldtype
(GH13900)
s = pd.SparseSeries([1.0, 0.0, 2.0, 0.0], fill_value=0)
s
s.astype(np.int64)
astype
如果数据包含无法转换为指定的值,则失败 dtype
。请注意,该限制适用于 fill_value
哪个是默认设置 np.nan
。
In [7]: pd.SparseSeries([1., np.nan, 2., np.nan], fill_value=np.nan).astype(np.int64)
Out[7]:
ValueError: unable to coerce current fill_value nan to int64 dtype
其他稀疏修复#
子类化
SparseDataFrame
和SparseSeries
现在,在切分或转置时保留类类型。 (GH13787 )SparseArray
使用bool
DTYPE现在支持逻辑(布尔)运算符 (GH14000 )Bug in
SparseSeries
withMultiIndex
[]
indexing may raiseIndexError
(GH13144)Bug in
SparseSeries
withMultiIndex
[]
indexing result may have normalIndex
(GH13144)Bug in
SparseDataFrame
in whichaxis=None
did not default toaxis=0
(GH13048)Bug in
SparseSeries
andSparseDataFrame
creation withobject
dtype may raiseTypeError
(GH11633)Bug in
SparseDataFrame
doesn't respect passedSparseArray
orSparseSeries
's dtype andfill_value
(GH13866)Bug in
SparseArray
andSparseSeries
don't apply ufunc tofill_value
(GH13853)Bug in
SparseSeries.abs
incorrectly keeps negativefill_value
(GH13853)多类型上的单行切片错误
SparseDataFrame
%s,类型以前被强制浮点 (GH13917 )窃听
SparseSeries
切片将整型数据类型更改为浮点型 (GH8292 )Bug in
SparseDataFarme
comparison ops may raiseTypeError
(GH13001)Bug in
SparseDataFarme.isnull
raisesValueError
(GH8276)Bug in
SparseSeries
representation withbool
dtype may raiseIndexError
(GH13110)窃听
SparseSeries
和SparseDataFrame
的bool
或int64
Dtype可能会显示其值,如下所示float64
数据类型 (GH13110 )使用稀疏索引时出现错误
SparseArray
使用bool
数据类型可能返回不正确的结果 (GH13985 )Bug in
SparseArray
created fromSparseSeries
may losedtype
(GH13999)Bug in
SparseSeries
comparison with dense returns normalSeries
rather thanSparseSeries
(GH13999)
索引器数据类型更改#
备注
此更改仅影响在Windows上运行的64位Python,并且仅影响相对高级的索引操作
方法,如 Index.get_indexer
它返回索引器数组,强制该数组为“Platform int”,以便它可以直接用于第三方库操作,如 numpy.take
。以前,平台int被定义为 np.int_
它对应于一个C整数,但正确的类型,也就是现在使用的类型是 np.intp
,它对应于可以容纳指针的C整数大小 (GH3033 , GH13972 )。
这些类型在许多平台上都是相同的,但对于Windows上的64位Python, np.int_
为32位,并且 np.intp
是64位。更改此行为可提高该平台上许多操作的性能。
以前的行为 :
In [1]: i = pd.Index(['a', 'b', 'c'])
In [2]: i.get_indexer(['b', 'b', 'c']).dtype
Out[2]: dtype('int32')
新行为 :
In [1]: i = pd.Index(['a', 'b', 'c'])
In [2]: i.get_indexer(['b', 'b', 'c']).dtype
Out[2]: dtype('int64')
其他API更改#
Timestamp.to_pydatetime
将发布一份UserWarning
什么时候warn=True
,并且该实例的纳秒数不为零,以前这将向标准输出输出一条消息 (GH14101 )。Series.unique()
WITH DATETIME和TIMEZONE现在返回Timestamp
使用时区 (GH13565 )。Panel.to_sparse()
将引发一个NotImplementedError
调用时出现异常 (GH13778 )。Index.reshape()
将引发一个NotImplementedError
调用时出现异常 (GH12882 )。.filter()
强制互斥关键字参数 (GH12399 )。eval
的上投规则float32
类型已更新,以便与NumPy的规则更一致。新行为不会向上转换为float64
如果你给一只Pandas繁衍后代float32
对象的浮点数64 (GH12388 )。一个
UnsupportedFunctionCall
如果NumPy不起作用,现在会引发错误np.mean
对分组对象或重采样对象调用 (GH12811 )。__setitem__
将不再将可调用的RHS作为函数应用,而不是将其存储。打电话where
直接获取之前的行为 (GH13299 )。Calls to
.sample()
will respect the random seed set vianumpy.random.seed(n)
(GH13161)Styler.apply
现在对您的函数必须返回的输出更加严格。为axis=0
或axis=1
,则输出形状必须相同。为axis=None
,则输出必须是具有相同列和索引标签的DataFrame (GH13222 )。Float64Index.astype(int)
现在将提高ValueError
如果Float64Index
包含NaN
值 (GH13149 )TimedeltaIndex.astype(int)
andDatetimeIndex.astype(int)
will now returnInt64Index
instead ofnp.array
(GH13209)通过
Period
多个频率恢复正常Index
现在返回Index
使用object
数据类型 (GH13664 )PeriodIndex.fillna
使用Period
现在有不同的频率强制到object
数据类型 (GH13664 )来自以下位置的分面框图
DataFrame.boxplot(by=col)
现在返回一个Series
什么时候return_type
并不是什么都没有。以前,这些函数返回一个OrderedDict
。请注意,当return_type=None
,默认情况下,它们仍返回二维NumPy数组 (GH12216 , GH7096 )。pd.read_hdf
现在将引发一个ValueError
而不是KeyError
,如果模式不是r
,r+
和a
是提供的。 (GH13623 )pd.read_csv()
,pd.read_table()
,以及pd.read_hdf()
抬高建筑物FileNotFoundError
在不存在的文件上调用时,Python3.x异常;这是后端为IOError
在Python2.x中 (GH14086 )More informative exceptions are passed through the csv parser. The exception type would now be the original exception type instead of
CParserError
(GH13652).pd.read_csv()
在C引擎中,现在将发出ParserWarning
或者募集一个ValueError
什么时候sep
编码的长度超过一个字符 (GH14065 )DataFrame.values
will now returnfloat64
with aDataFrame
of mixedint64
anduint64
dtypes, conforming tonp.find_common_type
(GH10364, GH13917).groupby.groups
will now return a dictionary ofIndex
objects, rather than a dictionary ofnp.ndarray
orlists
(GH14293)
不推荐使用#
Series.reshape
和Categorical.reshape
已被弃用,将在后续版本中删除 (GH12882 , GH12882 )PeriodIndex.to_datetime
has been deprecated in favor ofPeriodIndex.to_timestamp
(GH8254)Timestamp.to_datetime
has been deprecated in favor ofTimestamp.to_pydatetime
(GH8254)Index.to_datetime
andDatetimeIndex.to_datetime
have been deprecated in favor ofpd.to_datetime
(GH8254)pandas.core.datetools
模块已弃用,将在后续版本中删除 (GH14094 )SparseList
已被弃用,并将在未来版本中删除 (GH13784 )DataFrame.to_html()
andDataFrame.to_latex()
have dropped thecolSpace
parameter in favor ofcol_space
(GH13857)DataFrame.to_sql()
已不推荐使用flavor
参数,因为在未安装SQLAlChemy时该参数是多余的 (GH13611 )已弃用
read_csv
关键词:顶层
pd.ordered_merge()
已重命名为pd.merge_ordered()
在未来的版本中,原来的名字将被删除 (GH13358 )Timestamp.offset
property (and named arg in the constructor), has been deprecated in favor offreq
(GH12160)pd.tseries.util.pivot_annual
is deprecated. Usepivot_table
as alternative, an example is here (GH736)pd.tseries.util.isleapyear
已弃用,将在后续版本中删除。约会时间-喜欢现在有一个.is_leap_year
财产性 (GH13727 )Panel4D
andPanelND
constructors are deprecated and will be removed in a future version. The recommended way to represent these types of n-dimensional data are with the xarray package 。Pandas提供了一种to_xarray()
方法自动执行此转换。 (GH13564 )。pandas.tseries.frequencies.get_standard_freq
已弃用。使用pandas.tseries.frequencies.to_offset(freq).rule_code
取而代之的是 (GH13874 )pandas.tseries.frequencies.to_offset
'sfreqstr
keyword is deprecated in favor offreq
(GH13874)Categorical.from_array
已被弃用,并将在未来版本中删除 (GH13854 )
删除先前版本的弃用/更改#
这个
SparsePanel
类已被删除 (GH13778 )The
pd.sandbox
module has been removed in favor of the external librarypandas-qt
(GH13670)The
pandas.io.data
andpandas.io.wb
modules are removed in favor of the pandas-datareader package (GH13724).The
pandas.tools.rplot
module has been removed in favor of the seaborn package (GH13855)DataFrame.to_csv()
已经放弃了engine
参数,在0.17.1中已弃用 (GH11274 , GH13419 )DataFrame.to_dict()
has dropped theouttype
parameter in favor oforient
(GH13627, GH8486)pd.Categorical
已删除设置为ordered
属性,直接支持set_ordered
方法 (GH13671 )pd.Categorical
has dropped thelevels
attribute in favor ofcategories
(GH8376)DataFrame.to_sql()
已经放弃了mysql
选项,用于flavor
参数 (GH13611 )Panel.shift()
has dropped thelags
parameter in favor ofperiods
(GH14041)pd.Index
has dropped thediff
method in favor ofdifference
(GH13669)pd.DataFrame
has dropped theto_wide
method in favor ofto_panel
(GH14039)Series.to_csv
has dropped thenanRep
parameter in favor ofna_rep
(GH13804)Series.xs
,DataFrame.xs
,Panel.xs
,Panel.major_xs
,以及Panel.minor_xs
已经丢弃了copy
参数 (GH13781 )str.split
has dropped thereturn_type
parameter in favor ofexpand
(GH13701)删除传统时间规则(偏移量别名),自0.17.0起不再推荐使用(自0.8.0起一直是别名) (GH13590 , GH13868 )。现在遗留的时间规则提高了
ValueError
。有关当前支持的偏移的列表,请参见 here 。The default value for the
return_type
parameter forDataFrame.plot.box
andDataFrame.boxplot
changed fromNone
to"axes"
. These methods will now return a matplotlib axes by default instead of a dictionary of artists. See here (GH6581).这个
tquery
和uquery
中的函数pandas.io.sql
模块已移除 (GH5950 )。
性能改进#
Improved performance of sparse
IntIndex.intersect
(GH13082)改进了稀疏算法的性能
BlockIndex
当数据块数量较大时,尽管建议使用IntIndex
在这种情况下 (GH13082 )改进的性能
DataFrame.quantile()
因为它现在按区块运行 (GH11623 )改进了flat64哈希表操作的性能,修复了python3中一些非常慢的索引和GROUP BY操作 (GH13166 , GH13334 )
Improved performance of
DataFrameGroupBy.transform
(GH12737)Improved performance of
Index
andSeries
.duplicated
(GH10235)Improved performance of
Index.difference
(GH12044)Improved performance of
RangeIndex.is_monotonic_increasing
andis_monotonic_decreasing
(GH13749)Improved performance of datetime string parsing in
DatetimeIndex
(GH13692)Improved performance of hashing
Period
(GH12817)改进的性能
factorize
包含时区的日期时间 (GH13750 )通过在更大的索引上懒惰地创建索引哈希表来提高性能 (GH14266 )
Improved performance of
groupby.groups
(GH14293)在自查内存使用情况时不必要地具体化多索引 (GH14308 )
错误修复#
窃听
groupby().shift()
,当按缺少值的列分组时,这可能会在极少数情况下导致段错误或损坏 (GH13813 )窃听
groupby().cumsum()
算出cumprod
什么时候axis=1
。 (GH13994 )窃听
pd.to_timedelta()
其中errors
参数未被遵守 (GH13613 )窃听
io.json.json_normalize()
,其中非ascii密钥引发异常。 (GH13213 )Bug when passing a not-default-indexed
Series
asxerr
oryerr
in.plot()
(GH11858)如果启用了子图或在绘制后移动图例,则面积图绘制图例错误(需要matplotlib 1.5.0才能正确绘制面积图图例) (GH9161 , GH13544 )
窃听
DataFrame
对象类型为dtype的赋值Index
其中得到的列对于原始对象是可变的。 (GH13522 )Matplotlib中的错误
AutoDataFormatter
;这将恢复第二个缩放格式,并重新添加微秒缩放格式 (GH13131 )从以下位置选择时出现错误
HDFStore
具有固定的格式和start
和/或stop
现在将返回选定的范围 (GH8287 )窃听
Categorical.from_codes()
当一个无效的ordered
参数已传入 (GH14058 )窃听
Series
在不返回默认数据类型(Int64)的窗口上从整数元组构造 (GH13646 )窃听
TimedeltaIndex
带有类似DateTime对象的添加,其中未捕获添加溢出 (GH14068 )窃听
.groupby(..).resample(..)
当同一对象被多次调用时 (GH13174 )窃听
.to_records()
当索引名称为Unicode字符串时 (GH13172 )呼叫中出现错误
.memory_usage()
在未实现的对象上 (GH12924 )回归到
Series.quantile
使用NANS(还显示在.median()
和.describe()
);此外,现在命名Series
使用分位数 (GH13098 , GH13146 )窃听
SeriesGroupBy.transform
包含日期时间值和缺少的组 (GH13191 )Bug Where Empty
Series
在类似DateTime的数值操作中被错误地强制 (GH13844 )窃听
Categorical
构造函数在传递给Categorical
包含带有时区的日期时间 (GH14190 )Bug in
Series.str.extractall()
withstr
index raisesValueError
(GH13156)窃听
Series.str.extractall()
带有单个基团和量词 (GH13382 )Bug in
DatetimeIndex
andPeriod
subtraction raisesValueError
orAttributeError
rather thanTypeError
(GH13078)窃听
Index
和Series
创建方式:NaN
和NaT
混合数据可能没有datetime64
数据类型 (GH13324 )窃听
Index
和Series
可能会忽略np.datetime64('nat')
和np.timdelta64('nat')
推断数据类型 (GH13324 )Bug in
PeriodIndex
andPeriod
subtraction raisesAttributeError
(GH13071)窃听
PeriodIndex
构造返回float64
在某些情况下建立索引 (GH13067 )窃听
.resample(..)
使用一个PeriodIndex
不会更改其freq
适当地在为空时 (GH13067 )窃听
.resample(..)
使用一个PeriodIndex
不使用空值保留其类型或名称DataFrame
适当地在为空时 (GH13212 )窃听
groupby(..).apply(..)
当传递的函数返回每个组的标量值时 (GH13468 )。窃听
groupby(..).resample(..)
传递一些关键字会引发异常 (GH13235 )窃听
.tz_convert
在TZ-Aware上DateTimeIndex
这依赖于对索引进行排序以获得正确结果 (GH13306 )窃听
.tz_localize
使用dateutil.tz.tzlocal
可能返回不正确的结果 (GH13583 )窃听
DatetimeTZDtype
数据类型为dateutil.tz.tzlocal
不能被视为有效的数据类型 (GH13583 )窃听
pd.read_hdf()
尝试加载具有一个或多个分类列的单个数据集的HDF文件失败,除非将key参数设置为数据集的名称。 (GH13231 )窃听
.rolling()
方法的构造中允许使用负整数窗口。Rolling()
对象,但稍后在聚合时会失败 (GH13383 )窃听
Series
使用元组值数据和数值索引进行索引 (GH13509 )打印中出现错误
pd.DataFrame
其中不同寻常的元素与object
数据类型正在导致段错误 (GH13717 )排名中的BUG
Series
这可能会导致分段错误 (GH13445 )各种索引类型中的错误,不传播传递的索引的名称 (GH12309 )
Bug in
DatetimeIndex
, which did not honour thecopy=True
(GH13205)窃听
DatetimeIndex.is_normalized
在当地时区的情况下,标准化的DATE_RANGE返回不正确 (GH13459 )Bug in
pd.concat
and.append
may coercesdatetime64
andtimedelta
toobject
dtype containing python built-indatetime
ortimedelta
rather thanTimestamp
orTimedelta
(GH13626)窃听
PeriodIndex.append
五月份加薪AttributeError
当结果是object
数据类型 (GH13221 )Bug in
CategoricalIndex.append
may accept normallist
(GH13626)窃听
pd.concat
和.append
使用相同时区重置为UTC (GH7795 )窃听
Series
和DataFrame
.append
加薪AmbiguousTimeError
如果数据在DST边界附近包含日期时间 (GH13626 )窃听
DataFrame.to_csv()
其中,即使仅为非数值指定了引号,也引用了浮点值 (GH12922 , GH13259 )窃听
DataFrame.describe()
加薪ValueError
仅包含布尔列 (GH13898 )窃听
MultiIndex
在Level为非唯一时返回额外元素的切片 (GH12896 )窃听
.str.replace
不会引发TypeError
对于无效的更换 (GH13438 )窃听
MultiIndex.from_arrays
它没有检查输入数组长度是否匹配 (GH13599 )窃听
cartesian_product
和MultiIndex.from_product
它可能会在输入数组为空时引发 (GH12258 )窃听
pd.read_csv()
在极少数情况下,在对流/文件进行大块迭代时,这可能会导致段错误或损坏 (GH13703 )Bug in
pd.read_csv()
which caused errors to be raised when a dictionary containing scalars is passed in forna_values
(GH12224)窃听
pd.read_csv()
由于没有忽略BOM而导致BOM文件被错误解析 (GH4793 )Bug in
pd.read_csv()
withengine='python'
which raised errors when a numpy array was passed in forusecols
(GH12546)窃听
pd.read_csv()
参数将索引列解析为日期时,索引列被错误地解析为thousands
参数 (GH14066 )窃听
pd.read_csv()
使用engine='python'
其中NaN
将数据转换为数值后未检测到值 (GH13314 )窃听
pd.read_csv()
其中nrows
未为两个引擎正确验证参数 (GH10476 )窃听
pd.read_csv()
使用engine='python'
其中混合大小写形式的无穷大没有得到正确的解释 (GH13274 )窃听
pd.read_csv()
使用engine='python'
其中拖尾的NaN
值未被分析 (GH13320 )窃听
pd.read_csv()
使用engine='python'
当从一个tempfile.TemporaryFile
在装有Python3的Windows上 (GH13398 )窃听
pd.read_csv()
这阻止了usecols
阻止kwarg接受单字节Unicode字符串 (GH13219 )窃听
pd.read_csv()
这阻止了usecols
从一个空置的布景 (GH13402 )窃听
pd.read_csv()
在C引擎中,空字符没有被解析为空字符 (GH14012 )Bug in
pd.read_csv()
withengine='c'
in which NULLquotechar
was not accepted even thoughquoting
was specified asNone
(GH13411)窃听
pd.read_csv()
使用engine='c'
其中,当引号指定为非数字时,字段未正确转换为浮点型 (GH13411 )窃听
pd.read_csv()
在使用非UTF8编码的多字符分隔数据的Python2.x中 (GH3404 )窃听
pd.read_csv()
,其中utf-xx的别名(例如utf-xx、utf_xx、utf_xx)引发UnicodeDecodeError (GH13549 )窃听
pd.read_csv
,pd.read_table
,pd.read_fwf
,pd.read_stata
和pd.read_sas
其中,文件由解析器打开,但如果两者都打开,则不关闭chunksize
和iterator
是None
。 (GH13940 )窃听
StataReader
,StataWriter
,XportReader
和SAS7BDATReader
当出现错误时,文件未正确关闭。 (GH13940 )窃听
pd.pivot_table()
哪里margins_name
在以下情况下被忽略aggfunc
是一个列表 (GH13354 )Bug in
pd.Series.str.zfill
,center
,ljust
,rjust
, andpad
when passing non-integers, did not raiseTypeError
(GH13598)Bug in checking for any null objects in a
TimedeltaIndex
, which always returnedTrue
(GH13603)窃听
Series
算术提升TypeError
如果它包含类似DateTime的object
数据类型 (GH13043 )Bug
Series.isnull()
andSeries.notnull()
ignorePeriod('NaT')
(GH13737)Bug
Series.fillna()
andSeries.dropna()
don't affect toPeriod('NaT')
(GH13737Bug in
.fillna(value=np.nan)
incorrectly raisesKeyError
on acategory
dtypedSeries
(GH14021)创建扩展数据类型时出现错误,其中创建的类型不是/相同的 (GH13285 )
窃听
.resample(..)
IPython自省触发了不正确的警告 (GH13618 )Bug in
NaT
-Period
raisesAttributeError
(GH13071)Bug in
Series
comparison may output incorrect result if rhs containsNaT
(GH9005)窃听
Series
和Index
如果比较包含以下内容,可能会输出错误的结果NaT
使用object
数据类型 (GH13592 )窃听
Period
加薪TypeError
如果Period
在右手边 (GH13069 )Bug in
Period
andSeries
orIndex
comparison raisesTypeError
(GH13200)窃听
pd.set_eng_float_format()
这将阻止NaN和inf格式化 (GH11981 )Bug in
.unstack
withCategorical
dtype resets.ordered
toTrue
(GH13249)清除DateTime解析中的一些编译时警告 (GH13607 )
窃听
factorize
加薪AmbiguousTimeError
如果数据在DST边界附近包含日期时间 (GH13750 )窃听
.set_index
加薪AmbiguousTimeError
如果新指标包含DST边界和多层 (GH12920 )窃听
.shift
加薪AmbiguousTimeError
如果数据在DST边界附近包含日期时间 (GH13926 )窃听
pd.read_hdf()
时返回不正确的结果DataFrame
使用一个categorical
列和与任何值都不匹配的查询 (GH13792 )窃听
.iloc
使用非词法排序的多索引进行索引时 (GH13797 )Bug in
.loc
when indexing with date strings in a reverse sortedDatetimeIndex
(GH14316)窃听
Series
处理零维NumPy数组时的比较运算符 (GH13006 )Bug in
.combine_first
may return incorrectdtype
(GH7630, GH10567)窃听
groupby
哪里apply
根据第一个结果是否为None
或者不是 (GH12824 )Bug in
groupby(..).nth()
where the group key is included inconsistently if called after.head()/.tail()
(GH12839)窃听
.to_html
,.to_latex
和.to_string
静默忽略传递给formatters
关键词 (GH10690 )窃听
DataFrame.iterrows()
,而不是产生Series
子类(如果已定义 (GH13977 )窃听
pd.to_numeric
什么时候errors='coerce'
并且输入包含不可散列的对象 (GH13324 )Bug in invalid
Timedelta
arithmetic and comparison may raiseValueError
rather thanTypeError
(GH13624)Bug in invalid datetime parsing in
to_datetime
andDatetimeIndex
may raiseTypeError
rather thanValueError
(GH11169, GH11287)窃听
Index
使用TZ感知创建Timestamp
而且不匹配tz
选项错误地强制使用时区 (GH13692 )Bug in
DatetimeIndex
with nanosecond frequency does not include timestamp specified withend
(GH13672)Bug in
Series
when setting a slice with anp.timedelta64
(GH14155)窃听
Index
加薪OutOfBoundsDatetime
如果datetime
超过datetime64[ns]
界限,而不是强迫object
数据类型 (GH13663 )Bug in
Index
may ignore specifieddatetime64
ortimedelta64
passed asdtype
(GH13981)Bug in
RangeIndex
can be created without no arguments rather than raisesTypeError
(GH13793)窃听
.value_counts()
加薪OutOfBoundsDatetime
如果数据超过datetime64[ns]
边界 (GH13663 )Bug in
DatetimeIndex
may raiseOutOfBoundsDatetime
if inputnp.datetime64
has other unit thanns
(GH9114)窃听
Series
使用以下方式创建np.datetime64
它的单位不是ns
作为object
数据类型导致错误的值 (GH13876 )窃听
resample
使用时间增量数据,其中数据被强制转换为浮点型 (GH13119 )。Bug in
pd.isnull()
pd.notnull()
raiseTypeError
if input datetime-like has other unit thanns
(GH13389)Bug in
pd.merge()
may raiseTypeError
if input datetime-like has other unit thanns
(GH13389)窃听
HDFStore
/read_hdf()
弃置DatetimeIndex.name
如果tz
已设置好 (GH13884 )窃听
Categorical.remove_unused_categories()
变化.codes
将数据类型转换为平台int (GH13261 )窃听
groupby
使用as_index=False
在对包括分类列在内的多列进行分组时,返回所有NaN (GH13204 )窃听
df.groupby(...)[...]
哪里有宝石?Int64Index
引发错误 (GH13731 )分配给的CSS类中的错误
DataFrame.style
用于索引名称。以前,他们被分配到"col_heading level<n> col<c>"
哪里n
是级别数+1。现在它们被分配"index_name level<n>"
,在哪里n
是该多重索引的正确级别。BUG在哪里
pd.read_gbq()
可能会抛出ImportError: No module named discovery
由于与另一个名为apiclient的Python包的命名冲突 (GH13454 )窃听
Index.union
返回具有命名空索引的错误结果 (GH13432 )虫子进来了
Index.difference
和DataFrame.join
使用混合整数索引时在Python3中引发 (GH13432 , GH12814 )减去TZ感知中的错误
datetime.datetime
来自TZ-Awaredatetime64
系列 (GH14088 )窃听
.to_excel()
当DataFrame包含包含具有NaN值的标签的多索引时 (GH13511 )Bug in invalid frequency offset string like "D1", "-2-3H" may not raise
ValueError
(GH13930)窃听
concat
和groupby
对于具有以下功能的分层帧RangeIndex
级别 (GH13542 )。窃听
Series.str.contains()
对于仅包含以下内容的系列NaN
的价值object
数据类型 (GH14171 )Bug in
agg()
function on groupby dataframe changes dtype ofdatetime64[ns]
column tofloat64
(GH12821)与一起使用NumPy ufunc时出现错误
PeriodIndex
加或减整数升法IncompatibleFrequency
。请注意,使用标准运算符+
或-
建议使用,因为标准运营商使用更有效的路径 (GH13980 )Bug in operations on
NaT
returningfloat
instead ofdatetime64[ns]
(GH12941)Bug in
Series
flexible arithmetic methods (like.add()
) raisesValueError
whenaxis=None
(GH13894)窃听
DataFrame.to_csv()
使用MultiIndex
添加了零散空行的列 (GH6618 )窃听
DatetimeIndex
,TimedeltaIndex
和PeriodIndex.equals()
可能会回来True
当输入不是Index
但包含相同的值 (GH13107 )如果在DST边界附近包含DateTime,则针对DateTime和时区的赋值中的错误可能不起作用 (GH14146 )
窃听
pd.eval()
和HDFStore
使用python2截断长浮点型文字的查询 (GH14241 )窃听
Index
加薪KeyError
当列不在DF中并且列包含重复值时显示不正确的列 (GH13822 )窃听
Period
和PeriodIndex
在频率具有组合偏移别名时创建错误的日期 (GH13874 )窃听
.to_string()
使用整数调用时line_width
和index=False
引发Unound LocalError异常,因为idx
在分配之前被引用。窃听
eval()
其中resolvers
参数不接受列表 (GH14095 )虫子进来了
stack
,get_dummies
,make_axis_dummies
它不在(多)索引中保留分类数据类型 (GH13854 )PeriodIndex
can now acceptlist
andarray
which containspd.NaT
(GH13430)窃听
df.groupby
哪里.median()
如果分组的数据框包含空箱,则返回任意值 (GH13629 )窃听
Index.copy()
哪里name
参数被忽略 (GH14302 )
贡献者#
共有117人为此次发布贡献了补丁。名字中带有“+”的人第一次贡献了一个补丁。
Adrien Emery +
Alex Alekseyev
Alex Vig +
Allen Riddell +
Amol +
Amol Agrawal +
Andy R. Terrel +
Anthonios Partheniou
Ben Kandel +
Bob Baxley +
Brett Rosen +
Camilo Cota +
Chris
Chris Grinolds
Chris Warth
Christian Hudon
Christopher C. Aycock
Daniel Siladji +
Douglas McNeil
Drewrey Lupton +
Eduardo Blancas Reyes +
Elliot Marsden +
Evan Wright
Felix Marczinowski +
Francis T. O'Donovan
Geraint Duck +
Giacomo Ferroni +
Grant Roch +
Gábor Lipták
Haleemur Ali +
Hassan Shamim +
Iulius Curt +
Ivan Nazarov +
Jeff Reback
Jeffrey Gerard +
Jenn Olsen +
Jim Crist
Joe Jevnik
John Evans +
John Freeman
John Liekezer +
John W. O'Brien
John Zwinck +
Johnny Gill +
Jordan Erenrich +
Joris Van den Bossche
Josh Howes +
Jozef Brandys +
Ka Wo Chen
Kamil Sindi +
Kerby Shedden
Kernc +
Kevin Sheppard
Matthieu Brucher +
Maximilian Roos
Michael Scherer +
Mike Graham +
Mortada Mehyar
Muhammad Haseeb Tariq +
Nate George +
Neil Parley +
Nicolas Bonnotte
OXPHOS
Pan Deng / Zora +
Paul +
Paul Mestemaker +
Pauli Virtanen
Pawel Kordek +
Pietro Battiston
Piotr Jucha +
Ravi Kumar Nimmi +
Robert Gieseke
Robert Kern +
Roger Thomas
Roy Keyes +
Russell Smith +
Sahil Dua +
Sanjiv Lobo +
Sašo Stanovnik +
Shawn Heide +
Sinhrks
Stephen Kappel +
Steve Choi +
Stewart Henderson +
Sudarshan Konge +
Thomas A Caswell
Tom Augspurger
Tom Bird +
Uwe Hoffmann +
WillAyd +
Xiang Zhang +
YG-Riku +
Yadunandan +
Yaroslav Halchenko
Yuichiro Kaneko +
adneu
agraboso +
babakkeyvani +
c123w +
chris-b1
cmazzullo +
conquistador1492 +
cr3 +
dsm054
gfyoung
harshul1610 +
iamsimha +
jackieleng +
mpuels +
pijucha +
priyankjain +
sinhrks
wcwagner +
yui-knk +
zhangjinjie +
znmean +
颜发才(Yan Facai) +