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 =0 for submol in submols: for mol in mols: if mol.HasSubstructMatch(submol): count +=1 print(count)改变这段代码让输出的值为每个分子对应的count
时间: 2024-02-28 10:51:54 浏览: 35
您可以将计数变量 `count` 转换为一个字典,其中键为分子的 SMILES 字符串,值为该分子结构中匹配子结构的数量。代码如下:
```python
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 mol in mols:
count = 0
for submol in submols:
if mol.HasSubstructMatch(submol):
count += 1
count_dict[mol.ToSmiles()] = count
print(count_dict)
```
这将输出一个字典,其中键为每个分子的 SMILES 字符串,值为该分子匹配子结构的数量。
相关问题
df = pd.read_excel函数,具体
df = pd.read_excel是pandas库中的一个函数,用于读取Excel文件并将其转换为数据框(DataFrame)格式。该函数的具体参数和用法如下:
参数:
- Excel文件路径:可以是本地文件路径,也可以是网络上的URL路径。
- sheet_name:可选参数,用于指定要读取的Excel表格的名称或索引。默认情况下,它将读取第一个表格。
- header:可选参数,用于指定将哪一行作为列名。默认情况下,它将使用第一行作为列名。
- index_col:可选参数,用于指定哪一列作为索引列。
- skiprows:可选参数,用于跳过指定的行数。
- nrows:可选参数,用于指定读取的行数。
- usecols:可选参数,用于指定要读取的列范围。
- dtype:可选参数,用于指定列的数据类型。
- na_values:可选参数,用于指定在读取过程中将被视为缺失值的值。
用法示例:
```
import pandas as pd
# 读取本地Excel文件
df = pd.read_excel('data.xlsx')
# 读取网络上的Excel文件
df = pd.read_excel('https://example.com/data.xlsx')
# 读取指定表格和列范围的Excel文件
df = pd.read_excel('data.xlsx', sheet_name='Sheet1', usecols='A:C')
# 跳过前两行并指定第一列作为索引列
df = pd.read_excel('data.xlsx', skiprows=2, index_col=0)
```
通过使用这个函数,你可以方便地读取Excel文件中的数据并进行后续的数据分析和处理操作。
df = pd.read_excel
df = pd.read_excel是一个Python语言中的pandas库函数,用于读取Excel文件并将其转换为数据框(DataFrame)格式。该函数需要传入Excel文件的路径和文件名作为参数,例如:
df = pd.read_excel('data.xlsx')
其中,'data.xlsx'是Excel文件的路径和文件名。读取成功后,数据框df就可以用于数据分析和处理。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)