Python data is not loaded, so I'm asking you a question

Asked 2 years ago, Updated 2 years ago, 19 views

import numpy as np
import pandas as pd
data=[]

f= open('ls_orchid.fasta.csv')

running= True
while running:
    first_line = f.readline()
    if first_line == ' ' : break

    l=[first_line.strip()]
    s=' '
    for line in f:
        s+= line.strip()
    if line == '\n':
        break
    l.append(s)
    data.append(l)

f.close()

If you type data(0), you should get the data corresponding to the first paragraph of the file IndexError: list index out of range appears The file was changed to the csv extension and used If I type len(data), the number of data should come out, but it comes out as 0. What's wrong with that?

python

2022-09-22 18:22

1 Answers

l=[first_line.strip()] I recommend you to print (first_line) before and try debugging slowly

It's okay to learn a debugger called pdb, but I think it'll be okay to use print.


2022-09-22 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.