python - 从 json 格式的 csv 数据框单元格中查找特定值
问题描述
所以我有一个带有“cast”列的电影数据框。某部电影的第一个“演员”列如下所示:
[{'cast_id': 42, 'character': 'Ted the Bellhop', 'id': 3129, 'name': 'Tim Roth'},
{'cast_id': 31, 'character': 'Man', 'id': 3131, 'name': 'Antonio Banderas'},
{'cast_id': 29, 'character': 'Angela','id': 3130, 'name': 'Jennifer Beals'}]
我的问题是 - 我如何使用pandas.apply
这个值来整理这个看起来是 JSON 格式的值。我想通过查找所有“字符”来对这个值进行排序,所以我希望我的结果看起来像:
['Ted the Bellhop', 'Man', 'Angela']
解决方案
您也可以只使用地图功能来做到这一点。
cast = [
{
"cast_id":42,
"character":"Ted the Bellhop",
"id":3129,
"name":"Tim Roth"
},
{
"cast_id":31,
"character":"Man",
"id":3131,
"name":"Antonio Banderas"
},
{
"cast_id":29,
"character":"Angela",
"id":3130,
"name":"Jennifer Beals"
}
]
output = list(map(lambda x: x['character'], cast))
推荐阅读
- python - 如何扫描子网中的活动站点?
- ios - 使用 POST 请求的 Swift Alamofire
- python - PYTHON3:返回值的缩进
- xml - 如何在经典 ASP 中禁用 DTD 处理以防止 MSSOAP.SOAPClinet30 中的 XXE 攻击
- node.js - Nodejs:在主题交换中使用rabbitmq消息
- c# - 如何从另一个应用程序关闭 WPF 系统托盘应用程序?
- android-studio - 调用接口方法 java.lang.Object[] java.util.Collection.toArray() 时出现 Java NullPointerException
- intellij-idea - 如何获取“保存操作”代码格式以忽略注释
- python - 将元素附加到python中的数组列表之一
- php - 在 Wordpress 中将 SQL Server 表打印到网站?