Python Forum
error : value of a DataFrame is ambiguous
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error : value of a DataFrame is ambiguous
#1
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
Reply
#2
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:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Data cardinality is ambiguous: x sizes: 51 y sizes: 26 sidra 0 2,318 Oct-03-2020, 11:43 AM
Last Post: sidra
  strange error from pandas dataframe djf123 1 4,035 Jul-27-2020, 05:25 AM
Last Post: scidam
  error bars with dataframe and pandas Hucky 4 4,230 Apr-27-2020, 02:02 AM
Last Post: Hucky
  TensorFlow get error - array with more than one element is ambiguous vokoyo 3 5,543 Nov-07-2019, 01:12 PM
Last Post: ThomasL
  ValueError: The truth value of a Series is ambiguous ? firebird 1 4,322 Aug-01-2019, 12:33 AM
Last Post: scidam
  ValueError: The truth value of an array with more than one element is ambiguous. Eliza5 1 14,333 Apr-02-2018, 12:03 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020