[Tutor] Why Doesn't the for loop Increment?

Cameron Simpson cs at cskk.id.au
Thu Jan 14 16:30:56 EST 2021


On 14Jan2021 15:33, Stephen P. Molnar <s.molnar at sbcglobal.net> wrote:
>On 01/14/2021 02:35 PM, Dennis Lee Bieber wrote:
>>>DF =       7-Phloroeckol
>>>0       Aloeemodin
>>>1  beta-Sitosterol
>>	I don't know pandas but that looks suspiciously like a tabular result
>>(dataframe), where "Aloeemodin" and "beta-Sitosterol" are data items
>>associated with a category (?) heading of "7-Phloroeckol".
[...]
>Upon refection, I think that you are absolutely correct. That would 
>explain why there was no incrementation. In actuality there are going 
>to be quite a few more ligands, the first round that I am contemplating 
>will be 298, to be exact. [...]
>The question, and my problem, then becomes how do I get a list of 
>ligands into the script to extract the one number from each file?
>A solution would be greatly appreciated.

Well you've got 2 choices here. You could stick with the panda CSV stuff 
and put a heading on your CSV:

    ligand_name
    7-Phloroeckol
    Aloeemodin
    beta-Sitosterol

and process the dataframe DF as a single column dataframe.

Or you could do what my first instinct would be (since I've not had 
cause/time to use pandas) and _not_ treat the ligand file as a CSV.

    with open("ligands") as ligands_f:
        for line in ligands_f:
            ligand = line.strip()
            .... do the per-ligand stuff here ...

It's just a text file with a ligand name on each line. Open it and read 
it that way.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list