我有一个以teafiles格式保存的ohlc文件。我想将此信息放入pandas数据框。 要打开文件,请执行以下操作:
with TeaFile.openread(fullPathFileName) as tf:
numRecord = tf.itemcount
numFields = len(tf.description.itemdescription.fields)
for z in range(numFields):
fieldNames.append(tf.description.itemdescription.fields[z].name)
#for y in range(numRecord):
for y in range(5):
item = tf.read()
nums = []
for x in range(numFields):
tick = tf.description.itemdescription.fields[x]
nums.append(tf.getvaluestring(tick,item))
datas.append(nums)
然后我要将其放入熊猫数据框:
dframe = pd.DataFrame(data=datas,columns=fieldNames)
print(dframe.dtypes)
print(dframe)
我得到这个结果:
dateTime object
open float64
high int64
low int64
close int64
volume int64
dtype: object
dateTime open high low close volume
0 2018-08-20 06:00:00:000 2857.25 285725 285675 285675 2
1 2018-08-20 06:01:00:000 2856.75 285675 285675 285675 0
2 2018-08-20 06:02:00:000 2857.50 285750 285750 285750 1
3 2018-08-20 06:03:00:000 2857.50 285750 285750 285750 0
4 2018-08-20 06:04:00:000 2857.00 285700 285700 285700 2
有什么想法如何将此dateTime列转换为熊猫可识别的日期时间格式?
我尝试过:
dframe.iloc[:,0] = pd.to_datetime(dframe.iloc[:,0],infer_datetime_format=True)
但是我得到了
TypeError: <class 'teafiles.clockwise.DateTime'> is not convertible to datetime
这里有人来过吗?