`.loc`丢失时区,并使用datetime64 [ns] DateTimeIndex转换为`object`

时间:2020-07-01 15:23:52

标签: python pandas

datetime64[ns].loc(时区感知)索引DataFrame或Series是否有问题?

以下内容在最后一条语句中发出警告:

import numpy as np
import pandas as pd

N = 12
price = np.random.uniform(0, 100, N)
color = np.repeat(list("ABCD"), 3)
df = pd.DataFrame(dict(price=price, color=color),
                  index=pd.date_range("2020-01-01", periods=N,
                                      freq="100ms", tz="UTC"))
df["color"] = df["color"].astype("category")

price_grp = df["price"].groupby(df["color"])
color_idxmax = price_grp.idxmax()
df_sub = df.loc[color_idxmax]
/usr/lib/python3/dist-packages/pandas/core/common.py:250: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
    To accept the future behavior, pass 'dtype=object'.
    To keep the old behavior, pass 'dtype="datetime64[ns]"'.
  result = np.asarray(values, dtype=dtype)

详细信息

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.8.3.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.6.0-2-amd64
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : None
LANG             : en_CA.UTF-8
LOCALE           : en_CA.UTF-8

pandas           : 0.25.32
numpy            : 1.18.4
pytz             : 2020.1
dateutil         : 2.8.1
pip              : 20.1.1
setuptools       : 46.1.3
Cython           : None
pytest           : 4.6.11
hypothesis       : 5.16.0
sphinx           : 2.4.3
blosc            : 1.8.1
feather          : None
xlsxwriter       : None
lxml.etree       : 4.5.0
html5lib         : 1.0.1
pymysql          : None
psycopg2         : 2.8.5 (dt dec pq3 ext lo64)
jinja2           : 2.11.2
IPython          : 7.15.0
pandas_datareader: None
bs4              : 4.9.1
bottleneck       : 1.2.1
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.5.0
matplotlib       : 3.2.2
numexpr          : 2.7.1
odfpy            : None
openpyxl         : 3.0.3
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.4.1
sqlalchemy       : 1.3.15
tables           : 3.6.1
xarray           : 0.15.1
xlrd             : 1.1.0
xlwt             : 1.3.0
xlsxwriter       : None

0 个答案:

没有答案