Andres Azqueta Andres Azqueta - 6 months ago 29
Python Question

IndentationError: expected an indented block when trying to reproduce LDA for a document

I am trying to obtain the LDA distribution among the first article of my collection but I am running into several errors:

my collection:

doc_set
, is a
pandas.core.series.Series
. Whenever I wanted to run the simple code:

print(ldamodel[doc_set[1]])


I run the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Which I think I solved it by:

if doc_set is not None:
print(ldamodel[doc_set[1]])


Nevertheless, now I get the following error:
IndentationError: expected an indented block
. I am looking for the intuition of the error rather than the correction, I cannot put my whole LDA for reproduction because it is too massive. Thanks in advance!

Answer

Your indentation is incorrect because you didn't put your print statement inside the if block. If you end the line with a colon (:), you have to increase the indent level, or else you'll get an IndentationError exception.
This would be the correct code:

if doc_set is not None:
    print(ldamodel[doc_set[1]])
Comments