I want to make a function that first merges the duplicate entries by key in a dictionary, then removes the duplicate values in each key. However, I want the removed duplicates to be relative to the other values in the value list they’re in, not the value lists of the entire dictionary. If possible, could this…
How to efficiently loop over an image pixel by pixel in python OpenCV?
What I want to do is to loop over an image pixel by pixel using each pixel value to draw a circle in another corresponding image. My approach is as follows: Looping this way is somewhat slow. I tried adding the @njit decorator of numba, but apparently it has problems with opencv. Input images are 32×32 p…
Split string with a certain keyword outside a string but not inside a string
I have a question about how to use regex at this condition (or can be in any solution in Python): What I want to achieve is to split the colon ‘:’ if it’s found outside a string, but don’t split it if it’s inside a string, like this example below: Regex I use: (?!B”[^”…
I can’t update the content of a Kivy label from Python
I state that this is the first time I use Kivy. The code I attached works, the only problem is that the lbl label does not update automatically but only if I press the update button. In practice, if I call the update_lbl function via the “update” button it works, when it is called automatically by…
Get a specific line before specific line in txt file after comparison
I’m doing comparison between 2 txt files and i want to add before the difference lines the name of interface which contains this line to be like below :. First file contains : Second file contains : Code is as below : code result is like below : The code result which i need to be : Answer It’s not
how can I fix this program so it won’t return ‘unknown’ for negative input (boiling_point)
Here’s the given for the problem I’m trying to solve: *python Write a function that given a mapping from material to boiling points, and a boiling point temperature, will return : the material corresponding to the boiling, if it is within 5% difference ‘UNKNOWN’ otherwise Function sign…
I keep getting a TypeError and want the program to average a list
I keep getting the error – TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’ I have excluded most of the input code as it is long and not optimized. Answer it might be int(input()) not input(int()) instead. :D because int() is 0, but input() argument is a string not i…
Read, Split and Append csv to lists in python
Problem I need to build a backend function that will read the data within a csv file, split the values and append them to several lists. The program for adding/removing/displaying values form the lists is working but now I need to add file I/O. I have the file inventory.csv and have a function load_file_data(…
two conditions multiplication in pandas
I have the following dataframe, and I am trying to get revenue column by a multiplication between columnA or columnB and columnC. The condition is: if columnB is NaN, then the revenue column = columnA * columnC if columnB is not NaN, then the revenue column = columnB * columnC how do I get this revenue column…
how to add the value from the next row to the current row
I want to group by id column and add the value from the next row to the current row only for the trip column How can I transform the first data frame to the second data frame shown below? Answer I am not sure if the only thing requested is to concatenate the trip ID of the next row to