我有一个熊猫数据帧。
is_active Device
True 1
False 2
我有一个名为mapping.json的文件
[
{
"description": "Desktop",
"deviceId": "1"
},
{
"description": "Smartphone",
"deviceId": "2"
},
{
"description": "Tablet",
"deviceId": "3"
}
]
我需要从mapping.json中用设备id映射设备,以获得最终结果:
is_active Device
True Desktop
False Smartphone
我怎样才能用熊猫来实现它。
我正在做:
with open('mapping.json', 'r') as file:
c_map = json.load(file)
output_df['Device'] = output_df['Device'].map(c_map)
它给了我错误:TypeError:“list”对象不可调用