我是python的新手,我不知道为什么在df数据框中输入df ['smiles']命令时会收到错误消息。但是另一列可以通过df ['Name']命令完美显示。谁能帮我指出我所犯的错误。谢谢。
问题出在哪里?
我是python的新手,我不知道为什么在df数据框中输入df ['smiles']命令时会收到错误消息。但是另一列可以通过df ['Name']命令完美显示。谁能帮我指出我所犯的错误。谢谢。
问题出在哪里?
import pandas as pd
from rdkit.Chem import AllChem
from rdkit.Chem import Descriptors3D
import ternary
from ternary.helpers import simplex_iterator
import numpy as np
import matplotlib
from rdkit import Chem
import matplotlib.pyplot as plt
get_ipython().magic(u'matplotlib inline')
df = pd.read_csv('npsmiles.csv', encoding='cp1252')
df
````
Name smiles
0 Taxol O1[C@@H]2C[C@H](O)[C@@]3([C@H]([C@H](OC(=O)c4...
1 Actinonin OC[C@H]1N(CCC1)C(=O)[C@@H](NC(=O)[C@H](CCCCC)...
2 Discodermolide O1[C@@H](C[C@H](O)\C=C/[C@@H]([C@H](O)[C@H](\...
3 Validamycin O1[C@H](CO)[C@@H](O)[C@H](O)[C@@H](O)[C@@H]1O...
4 Monensin O1[C@@H]([C@H](C[C@@H](C)[C@]1(O)CO)C)[C@@H]1...
5 Calyculin A P(O[C@H]1[C@H](O[C@@]2(O[C@@H](C\C=C\c3nc(oc3...
6 Coformycin O1[C@H](CO)[C@@H](O)[C@@H](O)[C@@H]1n1c2NC=[N...
7 Arglabin O1[C@H]2[C@@H](CC[C@@]3(O[C@]34[C@@H]2C(=CC4)...
8 Mizoribine O1[C@H](CO)[C@@H](O)[C@@H](O)[C@@H]1n1cnc(C(=...
9 Forskolon O1[C@@]2(C)[C@@](O)([C@@]3([C@@H]([C@H](O)[C@...
10 SQ 26180 S(=O)(=O)([O-])N1C[C@](OC)(NC(=O)C)C1=O
11 Cephamycin C S1[C@H]2N(C(C(=O)[O-])=C(C1)COC(=O)N)C(=O)[C@...
12 Avermectin B1a O1[C@@H]2C[C@@]3(O[C@H]([C@H](CC)C)[C@H](C=C3...
13 Adriamycin O1[C@@H](C)[C@@H](O)[C@@H]([NH3+])C[C@@H]1O[C...
14 Phorbol myristate acetate O=C1[C@]2(O)[C@@H](C=C1C)[C@]1(O)[C@H]([C@H]3...
15 Thienamycin S(CC[NH3+])C=1C[C@H]2N(C=1C(=O)[O-])C(=O)[C@@...
16 Cyclosporin A O=C1N(C)[C@@H]([C@H](O)[C@@H](C\C=C\C)C)C(=O)...
17 FK506 O1[C@H](/C(=C/[C@H]2C[C@@H](OC)[C@H](O)CC2)/C...
18 Trapoxin B O1C[C@H]1C(=O)CCCCC[C@@H]1NC(=O)[C@@H]2N(CCC2...
19 Vincristine O(C)c1cc2N([C@@H]3[C@]4([C@H]5[NH+](CC=C[C@@]...
20 Colchicine O(C)C1=CC=C2c3c(cc(OC)c(OC)c3OC)CC[C@H](NC(=O...
21 Trichostatin A O=C([C@@H](\C=C(\C=C\C(=O)N[O-])/C)C)c1ccc(N(...
22 Fumagillin O1[C@](C)([C@H]2[C@H](OC)[C@H](OC(=O)\C=C\C=C...
23 Staurosporine O1[C@H]2n3c4c(c5c(CNC5=O)c5c6c(n(c45)[C@]1(C)...
24 Erythromycin A O1[C@H](CC)[C@](O)(C)[C@H](O)[C@@H](C)C(=O)[C...
25 Streptomycin O1[C@@H](CO)[C@H](O)[C@@H](O)[C@H]([NH2+]C)[C...
26 Penicillin G S1[C@H]2N([C@@H](C(=O)[O--])C1(C)C)C(=O)[C@H]...
27 Sperguallin O=C(N[C@@H](O)C(=O)NCCCC[NH2+]CCC[NH3+])C[C@@...
28 Rapamycin O1[C@@H](CC(=O)[C@@H](\C=C(/C)\[C@@H](O)[C@@H...
29 Echinocandin B Oc1ccc(cc1)[C@H](O)[C@@H](O)[C@@H]1NC(=O)[C@H...
30 Ginkgolide B O1[C@@H]2[C@@](O)([C@]34O[C@@H]5OC(=O)[C@H](O...
31 Vancomycin Clc1c2Oc3cc4[C@@H](NC(=O)[C@@H](NC(=O)[C@H](N...
32 Amphotericin B O1[C@@H](C)[C@H](C)[C@H](O)[C@H](\C=C\C=C\C=C...
33 Radicicol Clc1c2c(C(O[C@@H](C[C@H]3O[C@@H]3/C=C\C=C\C(=...
34 Salicylihalamide A O1[C@H](C[C@@H](O)[C@H](C\C=C\Cc2c(C1=O)c(O)c...
35 Telomestatin S1C2=N[C@H](c3oc(c(n3)-c3oc(c(n3)-c3occ(n3)-c...
36 Rifamycin B O1c2c3c4c(c(O)c2C)c(O)c(NC(=O)/C(=C\C=C\[C@H]...
37 Apoptolidin O1[C@@H](C[C@H](OC)[C@@H](O)CC\C=C(\C=C\[C@H]...
38 Midecamycin A1 O1[C@@H](C\C=C\C=C\[C@H](O)[C@@H](C[C@H](CC=O...
39 Zaragozic acid A O1[C@@]2(C(=O)[O-])[C@](O)(C(O)=O)[C@H](O[C@]...
40 Talaromycin B O1C[C@H](CO)[C@@H](O)C[C@]12OC[C@@H](CC2)CCS
41 Spongistatin 1 ClC(\C=C\[C@@H](O)CC(C[C@H]1O[C@H]2[C@H](O)[C...
42 Brevetoxin B O1[C@@H]2[C@H](O[C@@]3([C@H](O[C@@H]4[C@H](O[...
43 Quinine O(C)c1cc2c(nccc2[C@@H](O)[C@H]2[N@@H+]3C[C@@H...
44 Mycobactin S O1C[C@H](N=C1c1ccccc1O)C(=O)N[C@@H](CCCCN([O-...
45 Duocarmycin A O(C)c1c(OC)c2[nH]c(cc2cc1OC)C(=O)N1C=2[C@]3([...
46 Bleomycin A2 [S+](CCCNC(=O)c1nc(sc1)-c1nc(sc1)CCNC(=O)[C@@...
47 Brefeldin A O1[C@H](CCC\C=C\[C@H]2[C@@H](C[C@@H](O)C2)[C...
48 Cytochalasin B O1[C@@]23[C@@H]([C@H](C)C(=C)[C@@H](O)[C@@H]2...
49 Epothilone A s1cc(nc1C)\C=C(/C)\[C@H]1OC(=O)C[C@H](O)C(C)(...
50 Lactacystin S(C(=O)[C@@]1(NC(=O)[C@H](C)[C@@H]1O)[C@@H](O...
51 Calicheamicin 1 Ic1c(C)c(C(S[C@@H]2[C@H](O[C@@H](ON[C@H]3[C@H...
52 Artemisinin O1[C@@H]2O[C@@]3(OO[C@]24[C@@H](CC[C@H]([C@@H...
53 Compactin O1[C@@H](C[C@@H](O)CC1=O)CC[C@@H]1[C@@H]2C(C=...
54 Lipstatin O1[C@@H](C[C@@H](OC(=O)[C@@H](NC=O)CC(C)C)C\C...
55 Pseudomonic acid A O1[C@@H](C[C@H]2CO[C@@H](C\C(=C\C(OCCCCCCCCC(...
56 Daptomycin O1[C@H](C)[C@H](NC(=O)[C@@H](NC(=O)[C@H](NC(=...
57 Bestatin O=C(N[C@@H](CC(C)C)C(=O)[O-])[C@@H](O)[C@H]([...
58 Plaunotol OC/C(=C\CC\C(=C\CO)\C)/CC\C=C(\CC\C=C(\C)/C)/C
59 Geldanamycin O(C)C1=C2C[C@H](C[C@H](OC)[C@H](O)[C@H](\C=C(...
'df['Name']'
0 Taxol
1 Actinonin
2 Discodermolide
3 Validamycin
4 Monensin
5 Calyculin A
6 Coformycin
7 Arglabin
8 Mizoribine
9 Forskolon
10 SQ 26180
11 Cephamycin C
12 Avermectin B1a
13 Adriamycin
14 Phorbol myristate acetate
15 Thienamycin
16 Cyclosporin A
17 FK506
18 Trapoxin B
19 Vincristine
20 Colchicine
21 Trichostatin A
22 Fumagillin
23 Staurosporine
24 Erythromycin A
25 Streptomycin
26 Penicillin G
27 Sperguallin
28 Rapamycin
29 Echinocandin B
30 Ginkgolide B
31 Vancomycin
32 Amphotericin B
33 Radicicol
34 Salicylihalamide A
35 Telomestatin
36 Rifamycin B
37 Apoptolidin
38 Midecamycin A1
39 Zaragozic acid A
40 Talaromycin B
41 Spongistatin 1
42 Brevetoxin B
43 Quinine
44 Mycobactin S
45 Duocarmycin A
46 Bleomycin A2
47 Brefeldin A
48 Cytochalasin B
49 Epothilone A
50 Lactacystin
51 Calicheamicin 1
52 Artemisinin
53 Compactin
54 Lipstatin
55 Pseudomonic acid A
56 Daptomycin
57 Bestatin
58 Plaunotol
59 Geldanamycin
Name: Name, dtype: object
`df['smiles']`
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'smiles'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-49-ab79ecf9f855> in <module>
----> 1 df['smiles']
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
-> 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'smiles'
答案 0 :(得分:1)
找不到名为“微笑”的列 输入命令:
2020-09-08 16:07:14 64919 1 Status: Connecting to 9.9.9.9:21...
2020-09-08 16:07:15 64919 1 Status: Connection established, waiting for welcome message...
2020-09-08 16:07:15 64919 1 Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
2020-09-08 16:07:15 64919 1 Response: 220-You are user number 8 of 100 allowed.
2020-09-08 16:07:15 64919 1 Response: 220-Local time is now 10:07. Server port: 21.
2020-09-08 16:07:15 64919 1 Response: 220-This is a private system - No anonymous login
2020-09-08 16:07:15 64919 1 Response: 220-IPv6 connections are also welcome on this server.
2020-09-08 16:07:15 64919 1 Response: 220 You will be disconnected after 480 minutes of inactivity.
2020-09-08 16:07:15 64919 1 Command: AUTH TLS
2020-09-08 16:07:16 64919 1 Response: 234 AUTH TLS OK.
2020-09-08 16:07:16 64919 1 Status: Initializing TLS...
2020-09-08 16:07:17 64919 1 Status: Verifying certificate...
2020-09-08 16:07:17 64919 1 Status: TLS connection established.
2020-09-08 16:07:17 64919 1 Command: USER vince
2020-09-08 16:07:17 64919 1 Response: 331 User vince OK. Password required
2020-09-08 16:07:17 64919 1 Command: PASS **********
2020-09-08 16:07:18 64919 1 Response: 230-OK. Current directory is /
2020-09-08 16:07:18 64919 1 Response: 230 1 Kbytes used (0%) - authorized: 10240000 Kb
2020-09-08 16:07:18 64919 1 Command: SYST
2020-09-08 16:07:18 64919 1 Response: 215 UNIX Type: L8
2020-09-08 16:07:18 64919 1 Command: FEAT
2020-09-08 16:07:18 64919 1 Response: 211-Extensions supported:
2020-09-08 16:07:18 64919 1 Response: EPRT
2020-09-08 16:07:18 64919 1 Response: IDLE
2020-09-08 16:07:18 64919 1 Response: MDTM
2020-09-08 16:07:18 64919 1 Response: SIZE
2020-09-08 16:07:18 64919 1 Response: REST STREAM
2020-09-08 16:07:18 64919 1 Response: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
2020-09-08 16:07:18 64919 1 Response: MLSD
2020-09-08 16:07:18 64919 1 Response: AUTH TLS
2020-09-08 16:07:18 64919 1 Response: PBSZ
2020-09-08 16:07:18 64919 1 Response: PROT
2020-09-08 16:07:18 64919 1 Response: UTF8
2020-09-08 16:07:18 64919 1 Response: ESTA
2020-09-08 16:07:18 64919 1 Response: PASV
2020-09-08 16:07:18 64919 1 Response: EPSV
2020-09-08 16:07:18 64919 1 Response: SPSV
2020-09-08 16:07:18 64919 1 Response: 211 End.
2020-09-08 16:07:18 64919 1 Command: OPTS UTF8 ON
2020-09-08 16:07:18 64919 1 Response: 200 OK, UTF-8 enabled
2020-09-08 16:07:18 64919 1 Command: PBSZ 0
2020-09-08 16:07:19 64919 1 Response: 200 PBSZ=0
2020-09-08 16:07:19 64919 1 Command: PROT P
2020-09-08 16:07:19 64919 1 Response: 200 Data protection level set to "private"
2020-09-08 16:07:19 64919 1 Status: Logged in
2020-09-08 16:07:19 64919 1 Status: Retrieving directory listing...
2020-09-08 16:07:19 64919 1 Command: PWD
2020-09-08 16:07:19 64919 1 Response: 257 "/" is your current location
2020-09-08 16:07:19 64919 1 Command: TYPE I
2020-09-08 16:07:20 64919 1 Response: 200 TYPE is now 8-bit binary
2020-09-08 16:07:20 64919 1 Command: PASV
2020-09-08 16:07:20 64919 1 Response: 227 Entering Passive Mode (9,9,9,9,9,9)
2020-09-08 16:07:20 64919 1 Command: MLSD
2020-09-08 16:07:21 64919 1 Response: 150 Accepted data connection
2020-09-08 16:07:22 64919 1 Response: 226-Options: -a -l
2020-09-08 16:07:22 64919 1 Response: 226 37 matches total
2020-09-08 16:07:22 64919 1 Status: Directory listing of "/" successful
2020-09-08 16:11:57 64919 3 Command: TYPE I
2020-09-08 16:11:57 64919 3 Response: 200 TYPE is now 8-bit binary
2020-09-08 16:11:57 64919 3 Command: PASV
2020-09-08 16:11:57 64919 3 Response: 227 Entering Passive Mode (18,213,82,97,156,117)
2020-09-08 16:11:57 64919 3 Command: STOR test.txt.gz
2020-09-08 16:11:57 64919 3 Response: 150 Accepted data connection
2020-09-08 16:11:58 64919 3 Response: 226-1 Kbytes used (0%) - authorized: 10240000 Kb
2020-09-08 16:11:58 64919 3 Response: 226-File successfully transferred
2020-09-08 16:11:58 64919 3 Response: 226 0.047 seconds (measured here), 0.76 Kbytes per second
2020-09-08 16:11:58 64919 3 Status: File transfer successful, transferred 37 B in 1 second
2020-09-08 16:11:58 64919 3 Status: Retrieving directory listing of "/2nd"...
2020-09-08 16:11:58 64919 3 Command: PASV
2020-09-08 16:11:58 64919 3 Response: 227 Entering Passive Mode (9,9,9,9,9,9)
2020-09-08 16:11:58 64919 3 Command: MLSD
2020-09-08 16:11:59 64919 3 Response: 150 Accepted data connection
2020-09-08 16:11:59 64919 3 Response: 226-Options: -a -l
2020-09-08 16:11:59 64919 3 Response: 226 5 matches total
看到列名中可能有空格
答案 1 :(得分:1)
如果列前面有空格,则可以尝试使用skipinitialspace=True
:
df = pd.read_csv('npsmiles.csv', encoding='cp1252', skipinitialspace=True)