The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()?

Question:

The Code

indices =pd.Series(df_small)

indices[ : 5]

The Error

The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Asked By: Shrikanth Krish

||

Answers:

The reason might be that your dataframe df_small might have more than one column i.e it is not of Series datatype rather its a DataFrame, hence it is showing that error.

Try with only one column and you might not face the above error. For eg

indices = pd.Series(df_small.col1)
Answered By: vishnun
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.