Python Forum

Full Version: error : value of a DataFrame is ambiguous
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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: