pandas - 如何将列表的对象类型读入熊猫数据框?
问题描述
类型(输出)
列表
打印(输出)
个人资料(用户名='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 可序列化的
解决方案
尝试这个:
import pandas as pd
df = pd.DataFrame([profile.__dict__])
with profile 是您的类 Profile 的实例
推荐阅读
- python - GroupByKey 的光束类型提示
- android - Kotlin 和 Room 的 Dagger 2 错误
- linux-kernel - D中的内核模块
- python - 如何将 pyqtgraph IsocurveItem 实例与空绘图轴(而不是 ImageItem)对齐?
- android - 小于 21 的 API 级别中 translationZ 的 XML 替代
- python - Keras ImageDataGenerator 不同的图像
- r - 游戏周围的预测间隔
- java - 如何在所有 Java 类中使用 RabbitTemplate
- bash - Bash自定义功能更改目录
- php - 向现有笔记添加标签?