相关疑难解决方法(0)

我得到一个IndentationError.我如何解决它?

我有一个Python脚本:

if True:
    if False:
        print('foo')
   print('bar')
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行我的脚本时,Python提出了一个IndentationError:

  File "script.py", line 4
    print('bar')
               ^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

我一直在玩我的程序,我还能够产生其他三个错误:

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation

这些错误意味着什么?我究竟做错了什么?我该如何修复我的代码?

python error-handling code-formatting exception indentation

38
推荐指数
1
解决办法
2万
查看次数

熊猫如何使用pd.cut()

这是片段:

test = pd.DataFrame({'days': [0,31,45]})
test['range'] = pd.cut(test.days, [0,30,60])
Run Code Online (Sandbox Code Playgroud)

输出:

    days    range
0   0       NaN
1   31      (30, 60]
2   45      (30, 60]
Run Code Online (Sandbox Code Playgroud)

我很惊讶0不在(0,30),我应该怎么做才能将0归类为(0,30)?

python pandas

19
推荐指数
4
解决办法
4万
查看次数