match

How to improve performance of dataframe slices matching?

How to improve performance of dataframe slices matching? Question: I need to improve the performance of the following dataframe slices matching. What I need to do is find the matching trips between 2 dataframes, according to the sequence column values with order conserved. My 2 dataframes: >>>df1 trips sequence 0 11 a 1 11 d …

Total answers: 1

Check dataframe value to dictionary, append key to new column

Check dataframe value to dictionary, append key to new column Question: I am trying to check a row value for a match in a dictionary and append the key to a new column. Example: group_ID = { ‘Group A’:[4738, 4812], ‘Group B’:[5888, 6551], ‘Group C’:[4487, 7888] } user_data = [[‘Alex’,4812],[‘Bob’,4487],[‘Clarke’,5888]] sample_df = pd.DataFrame(user_data,columns=[‘Name’,’User ID’]) print(sample_df) …

Total answers: 2

How to not double print when matching multiple words in a sentence

How to not double print when matching multiple words in a sentence Question: Say we have the following sentence and words to match sentences = [‘There are three apples and oranges in the fridge.’, ‘I forgot the milk.’] wordsMatch = [‘apples’, ‘bananas’, ‘fridge’] How to iterate through the sentences and print them if there is …

Total answers: 1

Debugging in Hungarian Maximum Matching

Debugging in Hungarian Maximum Matching Question: I wrote a code to solve the following algorithm question: Given a number of positive integers all larger than 1, find the maximum number of pairs whose sum is a prime number. The number of positive integers is always an even number. For example, given 2 5 6 13 …

Total answers: 1

Match two pandas dataframe depending on multiple conditions

Match two pandas dataframe depending on multiple conditions Question: I have two datasets (df_persons and df_database). Both of them have the same structure: cu_id sex eye_colour favourite_sport cash_on_account 1 m blue soccer 15 2 f green tennis 25 3 m brown ski 33 (much more rows with various combinations of sex, eye_colour and favourite_sport) For …

Total answers: 1

How to use multiple cases in Match (switch in other languages) cases in Python 3.10

How to use multiple cases in Match (switch in other languages) cases in Python 3.10 Question: I am trying to use multiple cases in a function similar to the one shown below so that I can be able to execute multiple cases using match cases in python 3.10 def sayHi(name): match name: case [‘Egide’, ‘Eric’]: …

Total answers: 2

Python Match Case (Switch) Performance

Python Match Case (Switch) Performance Question: I was expecting the Python match/case to have equal time access to each case, but seems like I was wrong. Any good explanation why? Lets use the following example: def match_case(decimal): match decimal: case ‘0’: return "000" case ‘1’: return "001" case ‘2’: return "010" case ‘3’: return "011" …

Total answers: 3

How can I match a text with colon using regex?

How can I match a text with colon using regex? Question: I want to use regex to match any case with only 1 colon in front of a name or behind it, but not a name in between two colons. Matches things like this: name: | :name | name:`asdf` But should not match any of …

Total answers: 1

Determining Number of Groups Returned From Regex Search in Python

Determining Number of Groups Returned From Regex Search in Python Question: I’m performing a regex search in python like the one below: import re regexSearch = re.search(r’FTP-exception-sources-d{1,3}.d{1,3}.d{1,3}.d{1,3}’, line, re.M|re.I ) if regexSearch: outputFile2.write(str(lineCounter) + ” , ” + regexSearch.group(0) + “n”) How can I determine the number of groups that get returned from the regex …

Total answers: 1