Python Forum
error : value of a DataFrame is ambiguous - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: error : value of a DataFrame is ambiguous (/thread-26163.html)



error : value of a DataFrame is ambiguous - Sonata - Apr-22-2020

Hi everyone,

Regarding the code below:

import pandas as pd 
csv_path= links["file"]
df=pd.read_csv(csv_path)
if df.loc["0":"68","music":"music"]>8.5:
    print (pd.read_csv(csv_path))
I have this error message when I run it:

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

Someone have a solution, please ?

Thanks for help


RE: error : value of a DataFrame is ambiguous - anbu23 - Apr-24-2020

Multiple rows are selected in df.loc["0":"68","music":"music"]. If you want to check >8.5 against multiple rows, then you have to run it in loop.

Or if you want to print csv when any or all of the rows should be greater than 8.5 then try
if any(df.loc["0":"68","music":"music"])>8.5: