I want to build a canonical url for my website: my.com here are the requirements: always include www subdomain always use https protocol remove default 80 and 443 ports remove trailing slash Example: This is what I have tried: But I don’t know how to join these url components? Answer You just need to wr…
Tag: python
Swapping consecutive element in a list with a probability in Python
I want to swap consecutive elements in list with a probability. For example, I have this list: I wrote the following code thats swap the consecutive elements The above code results in the following : However, what I want to do is to use a probability for the swap. Let’s assume the probability of a swap …
Iterating row-wise over 2 pandas dataframes and passing these vectors as args to function
I’d like to iterate row-wise over 2 identically-shaped dataframes, passing the rows from each as vectors to a function without using loops. Essentially something similar to R’s mapply. I’ve investigated a little and the best that I’ve seen uses map in a list comprehension, but I’…
create threads within processes and share a queue between the threads
I am trying to create 3 threads within each of 2 processes and share a queue of the type multiprocessing.JoinableQueue among all threads. The worker_func function simply creates the threads while the thread_func function prints out the values it gets from the queue. The program gets stuck somewhere in the tim…
Concat string in column values where it is missing in Python
I have a dataframe I want to append string chr in column CHROM where it’s missing. I can do it in R with grepl and paste, but wanted to try in Python. I came up with these two commands, but not sure how to index the column because pd.Series is generating NaNs. Answer String operations in pandas are not …
how to convert bytes to binary using python
so i want convert bytes to binary in python, but when i run it, there’s none in the result and i got error: ‘NoneType’ object is not iterable here’s the code i tried Answer Your function currently returns None because there’s no return statement. Perhaps instead of using print, y…
Pandas Join Two Dataframes According to Range and Date
I have two dataframes like this: I want to bring the RATE values to the second df in accordance with the DATE. Also, the AMOUNT and DAY values in the relevant DATE must be within the appropriate range (MAX_AMOUNT & MIN_AMOUNT, MAX_DAY & MIN_DAY). Desired output like this: Could you please help me abou…
Loading a .tiff dataset in FiftyOne through browser
I have a .tiff image dataset that I want to load in FiftyOne. I’ve gone through the Docs and only found Geotiff dataType so I load it as a fiftyone.types.ImageDirectory. I got: Type image/tiff may not be supported. Came on SOF searching for a solution and came across this answer from Eric https://stackoverflo…
How to find the attribute and element id by selenium.webdriver?
I am learning web scrapping since I need it for my work. I wrote the following code: However, it is showing the following error: Then I inspect the table that I wanna scrape this table from this page what is the attribute that needs to be included in get_attribute() function in the following line? what I shou…
Iterate over Json with no list in python
I want to be able to iterate with the dictionary from Json that like how it is done with list. Getting below error. Expected: Should be able to use any of the key values inside for loop to iterate for each of the univ# block. ie., each univ# should a an item in for loop so that I can perform