0

I have written a piece of code in Pycharm which seems to execute flawlessly, but as soon as I put the code in Jupyter notebook I get the message : IndexError: list index out of range (Image)

Here is what my code looks like (Python) :

def parse_planets_file(fname):
    with open(fname) as f:
        inputm = f.readlines()
        method = inputm[0].split(",")
        del inputm[0]
        del method[0]
        data = {}
        for row in inputm:
            row = (row.strip()).split(",")
            if row[0] not in data:
                data[row[0]] = {h.strip(): [] for h in method}
            for i, h in enumerate(method):
                h = h.strip()
                data[row[0]][h].append(float(row[i + 1]) if row[i + 1] else row[i + 1])
        return data


fname = "exoplanets.csv"
print(parse_planets_file(fname))

The exact code in Pycharm executes and I get no error. Anyone able to help me out?

SKR01
  • 3
  • 4

0 Answers0