My task is creating a function that can find a score for different DataFrame objects that are passed into it, i settled on using if else statements to attempt to make a score, but i keep running into ValueError exceptions.
My data is all contained in dataframes as i collected it from csv files and performed analysis on them, will be using generic data for the purposes of the question here since i can't use the actual data for contract reasons.
df = pd.DataFrame(np.random.randint(0,1000,size=(1000)))
just using a generic random generated data frame just to see if i can make the idea work
def generic_function_name(self):
score=0
if ((df> 700) and (DF>500) and (DF>300)== True):
score += 3
if ((df>500) and (df>300) ==True):
score+=2
if ((df>300)== True):
score += 1
if ((df>300) ==False):
score +=0
print(score)
return
this is the function I've created, but I keep getting the following exception:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I'm sure someone much more competent than me will probably be horrified at my creation but I would please beg that you keep the laughter to a minimum while you explain just how wrong I am.
edits
Ok so following someof your suggestions i made changes to the function
def generic_function_name(self):
score=0
if ((df> 700)) :
score += 3
if ((df>500)):
score+=2
if ((df>300)):
score += 1
if ((df<300)):
score +=0
print(score)
return
then whed i do generic_function_name(df) it returns
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
so the problem is still their
df.head(20)
0
0 822
1 484
2 471
3 866
4 883
5 578
6 986
7 133
8 801
9 126
10 415
11 777
12 956
13 2
14 273
15 281
16 741
17 999
18 699
19 367
i have been informed im doing too many comparisons, and i feel i need to say that the events which this is a data is a generic version of have higher values which are equivalent to high danger that i need to look out for, and the middle and lower thresholds are meant to be equivalent to middle to low danger, which is why i had so many comparisons, since i want the score to include low to high dangers in the results, just was weighting the higher danger worth more to the score then the lower dangers.
if thier is an easier way please help me understand as i struggle with understanding how to create this score anyother way.