[英]pandas dataframe return wrong column value
Have a dataframe named results
, the to_csv()
function returns the following: 有一个名为results
的数据to_csv()
, 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
Now if I iterate over each rows and print the values 现在,如果我遍历每行并打印值
for i, r in results.iterrows():
print("======================================")
print(r)
print(r['startAt'])
print(r['endAt'])
it shows: 表明:
....(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'}
In another word, the startAt
and endAt
columes sometime returns {'iso': '2019-01-07T07:16:47.085000'}
instead of {'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}
. 换句话说, startAt
和endAt
有时会返回{'iso': '2019-01-07T07:16:47.085000'}
而不是{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}
。
How come? 怎么会?
Finally worked it out. 终于解决了。 Turns out the dataframe was partially constructed mistakenly, althought I am still confused how this error throws. 事实证明,数据帧是部分错误构造的,尽管我仍然对如何引发此错误感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.