为什么根据jupyter和spyder,“ i = 1”的语法无效? [关闭]

I want to create 50 random arrays and put them all in a dataframe. I'm realizing now that i should just do completeDF = pd.DataFrame(np.random.randint(0,100,size=(50, 10))) but this is just for practice / fun. My question isn't about the efficiency of what i'm doing. My question is about how jupyter and spyder are behaving weird. I've restarted them both before trying this.

我的问题是:

1) Why does jupyter and spyder think that i=0 is invalid syntax?

2)突然间,当我在第1行按Enter进入第2行时,它将光标6的选项卡带到应该位于的右边。为什么会这样?我怎么做才能使jupyter和spyder像这样?如果我将这段代码复制并粘贴到Spyder中,它将执行相同的操作。我已经在同一个Jupyter笔记本电脑中玩过熊猫和Numpy了一段时间,但它只是在这个单元中开始进行。其他细胞都很好。

在另一个单元格中,下面的简单代码执行得很好,并且当我转到下一行时,光标不会出现问题。

i=0
while i < 50:
    print(i)
    i+=1

这是给我带来问题的代码:


import numpy as np
import pandas as pd

# define completeDF to start with 
np.random.seed(0)
completeDF = pd.DataFrame(np.random.randint(0,100,size=(1, 10),dtype=int)


while i < 50:
    i=1
    np.random.seed(i)
    randomTen = np.random.randint(0,101,10) # rndomTen is an array
    randomTenisDF = pd.DataFrame(randomTen) 
    completeDF= pd.concat([completeDF], [randomTenisDF])
    i=i+1

print(completeDF)

输出:

  File "<ipython-input-11-f043bd7555e6>", line 9
    while i < 50:
        ^
SyntaxError: invalid syntax

if I put i=1 right before the while loop, the output is:


  File "<ipython-input-7-6b075a188843>", line 8
    i=1
    ^
SyntaxError: invalid syntax

The only solution i can think of if i see a cell behaving this way is to manually copy everything from the weird cell into a new cell. Copying and pasting into a new cell doesn't get rid of the weird extra tabs issue and the not accepting of i=0 syntax.