0

So I have a dataframe that I want to put each column in a separated list in order to compare them, but I get an index error : list assignment index out of range The code:

  for j in range (0, len(df.columns)):
      N=[]
      N[j]=N.append(df.loc[:,j]
  print('list' j, N[j])  

How can I avoid this error and get my desired results? Thanks in advance

  • The code you posted is weirdly capitalized (making it invalid Python). Can you please correct it? I've fixed it for syntax highlighting (don't dedent it to less than four characters), but I don't want to make other changes. – ShadowRanger Jul 14 '22 at 21:03
  • I corrected it, it's my first question here so – sahraoui khaoula Jul 14 '22 at 21:08
  • Umm... You removed the excess indentation, but you're still capitalizing several keywords and built-in functions (`for`, `len`, `print`). The indentation doesn't really matter (as long as it's at least four spaces to trigger code block format and it is indented legally for Python), the capitalization is the issue. – ShadowRanger Jul 14 '22 at 21:10
  • Welcome to Stack Overflow. When posting code, please try to make sure that it isn't being auto-corrected. Python is case sensitive. Ideally, post from a computer (not a phone), and copy and paste from an existing source file. Also, in general it is better to show [complete](https://meta.stackoverflow.com/questions/359146) errors, by copying and pasting, starting from the line that says `Traceback (most recent call last):`, and [formatting](https://stackoverflow.com/help/formatting) them like code. However, this problem is simple, and frequently asked about - please see the linked duplicate. – Karl Knechtel Jul 14 '22 at 21:13
  • I did search in the linked duplicate but I didn't find something that serve my purpose – sahraoui khaoula Jul 14 '22 at 21:23

0 Answers0