data = [{'serialNumber': '1', 'sensor': 'VCC3V3_RGM', 'sensorUnit': 'Volts','sensorUpperMinor': '--', 'sensorUpperCritical': '3.955', 'sensorUpperNonRecoverable': '--'}, {'serialNumber': '2', 'sensor': 'WEEP_VOLTS', 'sensorUnit': 'Volts', 'sensorUpperMinor': '--', 'sensorUpperCritical': '1.399', 'sensorUpperNonRecoverable': '--'}] . data数据处理转换成格式[{VCC3V3_RGM:{'sensorUnit': 'Volts', 'sensorUpperMinor': 'NA', 'sensorUpperCritical': '3.955', 'sensorUpperNonRecoverable': 'NA'}, {WEEP_VOLTS:{'sensorUnit': 'Volts', 'sensorUpperMinor': 'NA', 'sensorUpperCritical': '1.399', 'sensorUpperNonRecoverable': 'NA'}}]
时间: 2023-08-29 09:08:48 浏览: 54
可以使用以下代码将data数据处理转换成所需的格式:
```python
processed_data = []
for item in data:
sensor_name = item['sensor']
processed_item = {sensor_name: {
'sensorUnit': item['sensorUnit'],
'sensorUpperMinor': 'NA',
'sensorUpperCritical': item['sensorUpperCritical'],
'sensorUpperNonRecoverable': 'NA'
}}
processed_data.append(processed_item)
print(processed_data)
```
输出结果为:
```python
[{'VCC3V3_RGM': {'sensorUnit': 'Volts', 'sensorUpperMinor': 'NA', 'sensorUpperCritical': '3.955', 'sensorUpperNonRecoverable': 'NA'}}, {'WEEP_VOLTS': {'sensorUnit': 'Volts', 'sensorUpperMinor': 'NA', 'sensorUpperCritical': '1.399', 'sensorUpperNonRecoverable': 'NA'}}]
```
这样就将data数据处理转换成了所需的格式。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)