我在 Mac OS X 上使用 Pandas 0.11。我正在尝试使用 pandas 导入 csv 文件,文件read_csv
中的一列是完整的时间戳,其值如下:
fullts
1374087067.357464
1374087067.256206
1374087067.158231
1374087067.074162
我有兴趣获取后续时间戳之间的时间差,因此我将其导入并指定dtype
:
data = read_csv(fn, dtype={'fullts': float64})
但是,熊猫似乎将数字截断为其整数部分:
data.fullts.head(4)
产量:
1374087067
1374087067
1374087067
1374087067
有什么建议么?
谢谢!
补充:按照建议尝试使用pd.to_datetime
,并收到此错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-37ed0da45608> in <module>()
---> 1 pd.to_datetime(sd1.fullts)
/Users/user/anaconda/lib/python2.7/site-packages/pandas-0.11.0-py2.7-macosx-10.5-x86_64.egg/pandas/tseries/tools.pyc in to_datetime(arg, errors, dayfirst, utc, box, format)
102 values = arg.values
103 if not com.is_datetime64_dtype(values):
--> 104 values = _convert_f(values)
105 return Series(values, index=arg.index, name=arg.name)
106 elif isinstance(arg, (np.ndarray, list)):
/Users/user/anaconda/lib/python2.7/site-packages/pandas-0.11.0-py2.7-macosx-10.5-x86_64.egg/pandas/tseries/tools.pyc in _convert_f(arg)
84 else:
85 result = tslib.array_to_datetime(arg, raise_=errors == 'raise',
---> 86 utc=utc, dayfirst=dayfirst)
87 if com.is_datetime64_dtype(result) and box:
88 result = DatetimeIndex(result, tz='utc' if utc else None)
/Users/user/anaconda/lib/python2.7/site-packages/pandas-0.11.0-py2.7-macosx-10.5-x86_64.egg/pandas/tslib.so in pandas.tslib.array_to_datetime (pandas/tslib.c:15411)()
TypeError: object of type 'float' has no len()