-
Notifications
You must be signed in to change notification settings - Fork 0
/
rate_restrictions.py
46 lines (30 loc) · 1.37 KB
/
rate_restrictions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def overall_restrictions(df):
'''
If there are any rate restrictions, it returns the concatenated sentences containing the restrictions.
If there is no mention of restrictions, it returns 0.
Parameters:
df (DataFrame): Input DataFrame to check for restrictions.
Returns:
str or int: Concatenated string of sentences with restrictions or 0 if no restrictions found.
'''
# Convert all entries to strings
df = df.applymap(str)
# Define strings to check for
strings_to_check = ['rate', 'restricted', 'future', 'reference', 'banned', 'higher', 'restriction', 'special case']
# Initialize a list to collect matching rows
final_list = []
# Check for any matching strings in the DataFrame
mask = df.apply(lambda col: col.str.contains('|'.join(strings_to_check), case=False, na=False))
# Extract the rows where any column contains the strings
matching_rows = df[mask.any(axis=1)]
if matching_rows.empty:
return 0
# Concatenate the rows into a single string
final_list = '\n'.join(matching_rows.apply(lambda row: ' '.join(row), axis=1))
return final_list
def item_restriction(item, schedule, any_restriction, comparer, use_AI):
'''
It will return True or False
'''
return False
return restrictions