首页 > 解决方案 > 如何将列表的对象类型读入熊猫数据框?

问题描述

类型(输出)

列表

打印(输出)

个人资料(用户名='0000_',名称='ha',profile_photo='/pic/profile_images%2F712711040.jpg',tweet_count=159,following_count=89,followers_count=34,likes_count=118,is_verified=False,banner_photo=' /pic/profile_banners%2F2582365986%',传记='荣耀',user_id=255986,位置='',网站=无),

json.dumps(输出)

TypeError:Profile 类型的对象不是 JSON 可序列化的

标签: pandaslist

解决方案


尝试这个:

import pandas as pd
df = pd.DataFrame([profile.__dict__])

with profile 是您的类 Profile 的实例


推荐阅读