【发布时间】:2018-06-30 06:25:00
【问题描述】:
我有一个带有一列字符串的 pandas 数据框,日期时间为 UTC 格式,但需要将它们转换为浮点数。我很难做到这一点。这是我的专栏的视图:
df['time'][0:3]
0 2018-04-18T19:00:00.000000000Z
1 2018-04-18T19:15:00.000000000Z
2 2018-04-18T19:30:00.000000000Z
Name: time, dtype: object
我一直在尝试这个,但对我不起作用:
import datetime
for i in range(1,len(df)):
df['time'][i] = datetime.datetime.strptime(df['time'][i], '%Y-%m-%dT%H:%M:%S.%f000Z')
这是我要修复的错误:
execfile(filename, namespace)
exec(compile(f.read(), filename, 'exec'), namespace)
unsup.fit(np.reshape(df,(-1,df.shape[1])))
X = _check_X(X, self.n_components)
X = check_array(X, dtype=[np.float64, np.float32])
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: could not convert string to float: '2018-06-29T20:45:00.000000000Z'
提前非常感谢。
【问题讨论】:
标签: python string pandas dataframe utc