1 回答
TA贡献1784条经验 获得超7个赞
尝试:
from datetime import datetime
data2012 = np.loadtxt("try.txt", converters={0:lambda t: datetime.strptime(t.decode(), '%m-%d-%Y %H:%M')}, delimiter=','
, dtype={
'names': ('time', 'col1', 'col2', 'col3',),
'formats': ('datetime64[m]', 'float', 'float', 'float')
}
)
data2012
array([('2012-01-01T00:00', 0.36, -3.42, 0.76),
('2012-01-01T00:30', 0.35, -3.45, 0.75),
('2012-01-01T01:00', 0.35, -3.42, 0.76),
('2012-01-01T01:30', 0.36, -3.43, 0.76),
('2012-01-01T02:00', 0.36, -3.44, 0.75)],
dtype=[('time', '<M8[m]'), ('col1', '<f8'), ('col2', '<f8'), ('col3', '<f8')])
或者:
df = pd.read_csv("try.txt", header=None, date_parser=[0])
df
0 1 2 3
0 01-01-2012 00:00 0.36 -3.42 0.76
1 01-01-2012 00:30 0.35 -3.45 0.75
2 01-01-2012 01:00 0.35 -3.42 0.76
3 01-01-2012 01:30 0.36 -3.43 0.76
4 01-01-2012 02:00 0.36 -3.44 0.75
- 1 回答
- 0 关注
- 91 浏览
添加回答
举报