df =pd.read_excel("D:\HBVdata\HBV_P.xlsx") smile_list =df['Smiles'].tolist() mols =[Chem.MolFromSmiles(smile) for smile in smile_list] fingerprints =[Chem.RDKFingerprint(mol) for mol in mols] dg =pd.read_csv("D:\HBVdata\hbvfrag_recap_delete_duplicate.csv") smi_list =dg['mol'].tolist() submols =[Chem.MolFromSmarts(smi) for smi in smi_list] count_dict = {} for submol_idx, submol in enumerate(submols): count = 0 for mol in mols: if mol.HasSubstructMatch(submol): count += 1 smi = smi_list[submol_idx] count_dict[smi] = count counts =[count_dict.values()] total_count =sum(count_dict.values()) freq =[num / total_count for num in counts]针对这段代码分别将列表的值除以其总和
时间: 2024-02-28 15:56:15 浏览: 48
Read data from the Excel spreadsheet.zip_Spreadsheet::Read_excel
以下是代码实现:
```python
counts = list(count_dict.values())
total_count = sum(counts)
freq = [num / total_count for num in counts]
```
这里首先将字典中的值(即出现次数)提取出来,存储在列表 `counts` 中。然后使用 `sum()` 函数计算出列表中所有元素的总和。接着,使用列表推导式将列表中每个元素除以总和,得到频率列表 `freq`。
阅读全文