我有一个字典列表,在响应字段中有光谱数据。我还具有波长阵列,用于标记光谱数据的列。列表/输入看起来像这样:
data = [ {
'date': '2018-01-01',
'measurement': 100,
'responses': [(1, 1, np.array([1, 2, 3])),
(2, 1, np.array([4, 5, 6])),
]
},
{
'date': '2018-01-02',
'measurement': 200,
'responses': [(3, 1,np.array([5, 6, 7])),
(4, 1, np.array([8, 9, 10])),
]
},
]
以及要匹配的波长的列名称:
wavelengths = [400,401,402]
我想将此列表转换为两个熊猫数据框;
两者的期望输出如下:
__Average Dataframe__
index | date | measurement | 400 | 401 | 402 |
0 | '2018-01-01' | 100 | 2.5 | 3.5 | 4.5 |
1 | '2018-01-02' | 200 | 6.5 | 7.5 | 8.5 |
__Seperate Dataframe__
index | date | measurement | prong | scan| 400 | 401 | 402 |
0 | '2018-01-01' | 100 | 1 | 1 | 1 | 2 | 3 |
1 | '2018-01-01' | 100 | 2 | 1 | 4 | 5 | 6 |
2 | '2018-01-02' | 200 | 3 | 1 | 5 | 6 | 7 |
3 | '2018-01-02' | 200 | 4 | 1 | 8 | 9 | 10 |
在熊猫中最有效的方法是什么?
答案 0 :(得分:0)
这可能不是理想的解决方案,但使用;with mins as
(
select a.pid
,b.pid min_pid
from #j a
cross apply (
select top 1
b.*
from #j b
where b.name = a.name
and b.isdeleted = 0
order by b.pid
) b
where a.isdeleted = 0
)
update a
set pid = b.min_pid
from #e a
inner join mins b on b.pid = a.pid
:
pandas