[Tutor] Why Doesn't the for loop Increment?
Stephen P. Molnar
s.molnar at sbcglobal.net
Thu Jan 14 06:19:56 EST 2021
On 01/13/2021 07:23 PM, Alan Gauld via Tutor wrote:
> On 13/01/2021 21:00, Stephen P. Molnar wrote:
>
>>> df = pd.read_csv('ligands_3')
>>> print(df)
>>>
>>> for ligand in df:
>>> print(ligand)
>>> -=-=-=-
>>>
>>> Run ONLY that snippet and report with exactly what it prints.
>>>
>>>
>> df = pd.read_csv('ligands_3')
>> print(df)
>>
>> for ligand in df:
>> print(df)
> Note: Dennis asked to print ligand in the second print, not df again.
>
>
> But it would hekp to label the output so we know what we areseeing:
>
> print("DF= ", df)
>
> and
>
> print("Ligand = ", ligand
>
>
>> 7-Phloroeckol
>> 0 Aloeemodin
>> 1 beta-Sitosterol
>> 7-Phloroeckol
>> 0 Aloeemodin
>> 1 beta-Sitosterol
> Because its not clear abouve what output goes with what print.
> Well, actually it is here because you printed df twice....
> But if you print df and ligand we need to tell them, apart.
>
>
Excellent suggestion.
Here is the code with the print statements:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
df = pd.read_csv('ligands_3')
print('DF = ', df)
num = [1,2,3,4,5,6,7,8,9,10]
print('NUM = ', num)
for ligand in df:
print('LIGAND = ', ligand)
for i in num:
print('I = ', i)
name_in = "{}.{}.log".format(ligand, i)
print('NAME_IN =', name_in)
data = np.genfromtxt(name_in,skip_header=28, skip_footer=1)
print('DATA = ', data)
name_s = ligand+'-BE'
print('NAME_S =', name_s)
f = open(name_s, 'a')
f.write(str(data[0,1])+'\n')
print('DATA[0,1] = ', data[0,1])
f.close()
Here are the results:
DF = 7-Phloroeckol
0 Aloeemodin
1 beta-Sitosterol
NUM = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
LIGAND = 7-Phloroeckol
I = 1
NAME_IN = 7-Phloroeckol.1.log
DATA = [[ 1. -9.24815359 0. 0. ]
[ 2. -8.77018617 4.382 11.138 ]
[ 3. -8.71121521 2.155 9.423 ]
[ 4. -8.69308629 5.334 11.567 ]
[ 5. -8.66932661 4.935 11.596 ]
[ 6. -8.43895798 4.145 10.894 ]
[ 7. -8.22467105 2.364 8.799 ]
[ 8. -8.20285633 4.968 9.419 ]
[ 9. -8.19827601 2.291 8.099 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.248153586
I = 2
NAME_IN = 7-Phloroeckol.2.log
DATA = [[ 1. -9.17474926 0. 0. ]
[ 2. -8.76125135 4.477 11.177 ]
[ 3. -8.62503496 2.549 9.246 ]
[ 4. -8.51929251 5.321 10.904 ]
[ 5. -8.32529487 6.085 12.541 ]
[ 6. -8.27908207 6.051 12.457 ]
[ 7. -8.23362526 5.207 11.747 ]
[ 8. -8.22360117 5.284 11.396 ]
[ 9. -8.1552274 4.603 11.329 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.174749259
I = 3
NAME_IN = 7-Phloroeckol.3.log
DATA = [[ 1. -8.94101715 0. 0. ]
[ 2. -8.14939511 1.608 2.504 ]
[ 3. -8.12218651 2.139 3.186 ]
[ 4. -7.95106339 19.754 23.455 ]
[ 5. -7.94903298 1.795 3.034 ]
[ 6. -7.87858203 2.159 2.52 ]
[ 7. -7.84398855 2.244 3.116 ]
[ 8. -7.83202941 2.66 4.225 ]
[ 9. -7.70585579 27.441 32.52 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -8.941017151
I = 4
NAME_IN = 7-Phloroeckol.4.log
DATA = [[ 1. -9.16256247 0. 0. ]
[ 2. -9.00875388 17.317 22.896 ]
[ 3. -8.76733608 4.486 11.171 ]
[ 4. -8.67364017 5.072 11.659 ]
[ 5. -8.52560114 4.954 11.513 ]
[ 6. -8.31454518 5.833 12.473 ]
[ 7. -8.17565187 4.665 11.309 ]
[ 8. -8.1713394 3.529 10.53 ]
[ 9. -8.14095062 2.225 9.547 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.162562472
I = 5
NAME_IN = 7-Phloroeckol.5.log
DATA = [[ 1. -9.17411506 0. 0. ]
[ 2. -8.8841462 5.333 11.643 ]
[ 3. -8.77081732 4.476 11.169 ]
[ 4. -8.62460864 2.552 9.244 ]
[ 5. -8.44033143 5.428 11.144 ]
[ 6. -8.33375966 5.844 12.486 ]
[ 7. -8.30255093 6.09 12.539 ]
[ 8. -8.15969455 4.608 11.328 ]
[ 9. -8.12005716 5.161 11.509 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.17411506
I = 6
NAME_IN = 7-Phloroeckol.6.log
DATA = [[ 1. -9.21752813 0. 0. ]
[ 2. -8.77520263 4.762 8.699 ]
[ 3. -8.68887368 4.926 11.579 ]
[ 4. -8.62601653 2.44 9.186 ]
[ 5. -8.59648372 5.352 11.044 ]
[ 6. -8.54099385 4.857 11.467 ]
[ 7. -8.44948087 5.404 11.073 ]
[ 8. -8.35845922 5.595 12.356 ]
[ 9. -8.33891506 2.213 8.436 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.217528128
I = 7
NAME_IN = 7-Phloroeckol.7.log
DATA = [[ 1. -9.13303038 0. 0. ]
[ 2. -8.6670965 3.327 6.935 ]
[ 3. -8.6251615 1.807 2.586 ]
[ 4. -8.33583451 3.692 8.01 ]
[ 5. -8.22558254 2.925 3.56 ]
[ 6. -8.11645005 2.539 3.359 ]
[ 7. -8.0962971 3.272 7.159 ]
[ 8. -8.0926511 3.148 6.203 ]
[ 9. -8.08398821 1.936 2.303 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.133030378
I = 8
NAME_IN = 7-Phloroeckol.8.log
DATA = [[ 1. -9.18235525 0. 0. ]
[ 2. -8.67150999 3.414 6.913 ]
[ 3. -8.51768291 3.213 11.461 ]
[ 4. -8.46914231 3.628 6.385 ]
[ 5. -8.44830485 3.113 10.84 ]
[ 6. -8.3596531 3.637 7.896 ]
[ 7. -8.27598525 2.886 3.775 ]
[ 8. -8.26197225 1.969 3.09 ]
[ 9. -8.18242741 3.622 6.408 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.182355251
I = 9
NAME_IN = 7-Phloroeckol.9.log
DATA = [[ 1. -9.29877154 0. 0. ]
[ 2. -9.04913298 3.136 6.735 ]
[ 3. -9.0223066 2.33 9.597 ]
[ 4. -8.95225114 2.821 5.26 ]
[ 5. -8.80905279 1.812 2.432 ]
[ 6. -8.73525232 2.965 5.919 ]
[ 7. -8.62100389 2.822 5.276 ]
[ 8. -8.5245415 3.515 7.867 ]
[ 9. -8.44223426 2.803 3.531 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.298771543
I = 10
NAME_IN = 7-Phloroeckol.10.log
DATA = [[ 1. -9.30057716 0. 0. ]
[ 2. -9.25630706 0.387 2.023 ]
[ 3. -9.22213674 2.752 9.371 ]
[ 4. -8.97532518 3.228 6.707 ]
[ 5. -8.87955892 2.877 5.421 ]
[ 6. -8.616238 3.09 6.056 ]
[ 7. -8.44447012 3.477 7.787 ]
[ 8. -8.30902987 3.338 10.74 ]
[ 9. -8.29915536 3.162 6.544 ]]
NAME_S = 7-Phloroeckol-BE
DATA[0,1] = -9.300577161
The resulting, saved, file 7-Phloroeckol-BE:
-9.248153586
-9.174749259
-8.941017151
-9.162562472
-9.17411506
-9.217528128
-9.133030378
-9.182355251
-9.298771543
-9.300577161
--
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype: smolnar1
More information about the Tutor
mailing list