将pandas.DatetimeIndex从[ns]舍入为[s]

时间:2014-06-17 08:31:03

标签: python numpy pandas

所以我有这个索引的数据框

print df.index

结果:

<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 11:30:16.624989600, ..., 2000-01-01 11:50:33.124011100]
Length: 240178, Freq: None, Timezone: None

我想要几秒钟,例如:

<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 11:30:16.625, ..., 2000-01-01 11:50:33.124]
Length: 240178, Freq: None, Timezone: None

或者

<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01 11:30:16.625000000, ..., 2000-01-01 11:50:33.124000000]
Length: 240178, Freq: None, Timezone: None

所以我使用datetimeindex.round()方法

print df.index.round(decimals=3)

有这样的结果:

TypeError
Traceback (most recent call last) <ipython-input-9-6e2dbd74ae75> in <module>()
      1 print df.index
----> 2 print df.index.round(decimals=3) TypeError: ufunc multiply cannot use operands with types dtype('<M8[ns]') and dtype('float64')

该方法尚不可用吗?

编辑:

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.14.0
nose: 1.3.1
Cython: 0.20.1
numpy: 1.8.1
scipy: 0.13.3
statsmodels: 0.5.0
IPython: 2.0.0
sphinx: 1.2.2
patsy: 0.2.1
scikits.timeseries: None
dateutil: 2.2
pytz: 2013.9
bottleneck: None
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.3.1
openpyxl: None
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
bq: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None

0 个答案:

没有答案