-2

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!

Economist_Ayahuasca
  • 1,648
  • 24
  • 33
  • 2
    Whitespace is crucial in Python. Every block must be indented. You said `if ...`, so presumably you want to put something in that block. Since you didn't indent your `print` call, Python thinks you didn't put anything in the block. Just indent that line. – zondo May 26 '16 at 10:02

2 Answers2

1

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]])
illright
  • 3,991
  • 2
  • 29
  • 54
1

indentation are very peculiar in python. You have to maintain the heirarchy, either by using white-spaces or tabs for each block. Each block can only have either the tabs or (any number of) white spaces.

for item in list:
    print item

if flag:
  raise SystemExit

In first block of code, i used four white space and in second i used two.

Same is the case for the COMMENTS. Comments must be indented accordingly.

print 'Starting module'
if not configs:
    '''
    sys.exit('Error in Configuration files.')
    '''
    pass

In this case the line is meant to be commented and python does not complain. Otherwise it will throw error regarding the indentation.

Umair Bhatti
  • 117
  • 1
  • 4