1
from StringIO import StringIO
import datetime as dt
import pandas as pd
def addtime(temp):
temp = (temp) + (dt.timedelta(hours =16))
return(temp)
data = """\
'12-31-2012',5100, 5200
'01/1/2013',5300,5400"""
tdata = pd.read_csv(StringIO(data),
names = ['date', 'field1', 'field'], index_col = None,
parse_dates =['date'], header= None)
print tdata
old_date = tdata.ix[0,'date']
print 'old date =',old_date
new_date = addtime(old_date)
print 'new date =',new_date
# date field1 field
#0 2012-12-31 00:00:00 5100 5200
#1 2013-01-01 00:00:00 5300 5400
#old date = 2012-12-31 00:00:00
#new date = 2012-12-31 16:00:00
我想为每个日期添加16个小时作为Pandas CSV阅读器的一部分。但我无法弄清楚如何添加“parse_dates =”的工作。示例代码正确执行操作,而不是以所需的方式。帮助将不胜感激。pandas csv阅读器中的日期转换
谢谢你,我没有得到/使用正确的形式为您添加到更新时间解析器声明。 – 2013-03-17 21:07:33