Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从数据帧的两列中提取值,以生成键和值的字典_Python_Pandas_Dictionary - Fatal编程技术网

Python 从数据帧的两列中提取值,以生成键和值的字典

Python 从数据帧的两列中提取值,以生成键和值的字典,python,pandas,dictionary,Python,Pandas,Dictionary,我有一个包含几列数据的数据框。如果有两列“反应”和“丰度”。其中每一项都会多次显示,例如: reaction product abundance 1.0 1.5 2.0 2.5 3.0 3.5 4.0 ... \ 0 023Na-a 010020.tot 1 0 0 0 0 0 0 0 ... 1 023Na-a 012023.tot 1 0 0 0 0 0 0 0 ...

我有一个包含几列数据的数据框。如果有两列“反应”和“丰度”。其中每一项都会多次显示,例如:

    reaction     product abundance 1.0 1.5 2.0 2.5 3.0 3.5 4.0  ...  \
0    023Na-a  010020.tot       1   0   0   0   0   0   0   0  ...   
1    023Na-a  012023.tot       1  0   0   0   0   0   0   0  ...   
2    035Cl-a  010022.tot       0.3775   0   0   0   0   0   0   0  ...   
3    035Cl-a  008018.tot       0.3775   0   0   0   0   0   0   0  ...   
4    037Cl-a  013025.tot       0.1195   0   0   0   0   0   0   0  ...   
..       ...         ...       ...  ..  ..  ..  ..  ..  ..  ..  ...   
对于每个反应实例,丰度都是相同的。我想创建一本关于反应和丰富性的词典:

dict = {'023Na-a': 1, 
        '035Cl-a': 0.3775, 
        '037Cl-a': 0.1195} 
结果

{'023Na-a': 1.0, '035Cl-a': 0.3775, '037Cl-a': 0.1195}
结果

{'023Na-a': 1.0, '035Cl-a': 0.3775, '037Cl-a': 0.1195}