具有一个名为results
的数据帧,to_csv()
函数返回以下内容:
data,endAt,sn,startAt,type
{},"{'__type': 'Date', 'iso': '2019-01-07T07:16:47.085000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T07:10:35.859000'}",loss
{},"{'__type': 'Date', 'iso': '2019-01-07T08:10:46.016000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T08:04:34.957000'}",loss
{},"{'__type': 'Date', 'iso': '2019-01-07T08:28:16.712000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}",loss
{},"{'__type': 'Date', 'iso': '2019-01-07T07:16:47.085000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T07:10:35.859000'}",low_current
{},"{'__type': 'Date', 'iso': '2019-01-07T08:10:46.016000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T08:04:34.957000'}",low_current
{},"{'__type': 'Date', 'iso': '2019-01-07T08:28:16.712000'}",1c11020003,"{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}",low_current
现在,如果我遍历每行并打印值
for i, r in results.iterrows():
print("======================================")
print(r)
print(r['startAt'])
print(r['endAt'])
它显示:
....(skip some lines)
======================================
data {}
endAt {'__type': 'Date', 'iso': '2019-01-07T08:28:16...
sn 1c11020003
startAt {'__type': 'Date', 'iso': '2019-01-07T08:21:53...
type loss
Name: 2, dtype: object
{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}
{'__type': 'Date', 'iso': '2019-01-07T08:28:16.712000'}
======================================
data {}
endAt {'iso': '2019-01-07T07:16:47.085000'}
sn 1c11020003
startAt {'iso': '2019-01-07T07:10:35.859000'}
type low_current
Name: 3, dtype: object
{'iso': '2019-01-07T07:10:35.859000'}
{'iso': '2019-01-07T07:16:47.085000'}
换句话说,startAt
和endAt
枚举有时会返回{'iso': '2019-01-07T07:16:47.085000'}
而不是{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}
。
怎么来?
答案 0 :(得分:0)
最后解决了。事实证明,数据帧是部分错误构造的,尽管我仍然很困惑此错误的引发方式。