繁体   English   中英

熊猫数据框返回错误的列值

[英]pandas dataframe return wrong column value

有一个名为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

现在,如果我遍历每行并打印值

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'}

换句话说, startAtendAt有时会返回{'iso': '2019-01-07T07:16:47.085000'}而不是{'__type': 'Date', 'iso': '2019-01-07T08:21:53.127000'}

怎么会?

终于解决了。 事实证明,数据帧是部分错误构造的,尽管我仍然对如何引发此错误感到困惑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM