数据帧列中的单元格是单个列表。数据类型列表不工作

2024-09-28 01:32:36 发布

您现在位置:Python中文网/ 问答频道 /正文

dtype_dict = {'_id':str, 'userId':str, 'ownName':str, 'created_time':str, 'created_by':str,
   'addressInputList':list, 'displayName':str, 'emailInputList':list,
   'groupInputList':list, 'imInputList':list, 'lastContactedTime':int,
   'lastUpdatedTime':int, 'noOfTimesContacted':int, 'notes':str, 'orgInputList':list,
   'phoneNumberInputList':list, 'relationInputList':list, 'id':str,
   'inputTakenTime':str}
contacts = pd.read_csv("All-Fri Apr 15 2016 13_45_57 GMT+0530 (IST).csv", dtype=dtype_dict)
print contacts.dtypes
print contacts["phoneNumberInputList"][1]

我得到的结果是:

enter image description here

我检查了csv文件的每一行,但是csv文件的格式是一致的。该列(phoneNumberInputList)是所有行中的正确列表。请指出我在哪里犯了错误,以及如何将该列(以及其他类似列)作为数据类型列表来阅读。你知道吗


Tags: 文件csvid列表dictlistintcontacts
1条回答
网友
1楼 · 发布于 2024-09-28 01:32:36

好吧,这不是正确的方法,但我发现了一个黑客。使用graphlab sframe读取dtype为list的列,然后使用.to\ dataframe命令将该sframe转换为dataframe。你知道吗

相关问题 更多 >

    热门问题