I’m trying to look in a dataframe, and find the median of data within a column based on another column. I have a dataframe with ‘zipcode’ data and ‘price’ data. I want to find the median of the ‘price’ based on the ‘zipcode’, and report it in a new column.…
Tag: python
How to rename subfolders by numerical pattern and order based on theirs parent in python
I have a folder with many sub-folders, and each sub-folder also has two sub-folders. The structure looks like this: What I want to achieve is extract the folder with smaller number in name(in the above example, 1-1000, 1-1030 and 1-1040) and rename these folders according to their parent folders(sub-f1-1, sub…
Why selenium is not starting next url after quiting the previous url
Actully I’m working on some URLs. URLs are store in my database while picking one by one and looking for it resources and storing that resources in a database. if I do this with out using driver.quit() somehow for everyurl it store information from the beginning so I decide to use driver.quit now it wor…
Sort one inside another
I have a class Person that contains names and hobbies. Then there’s a list that contains people. person1 = Person(“MarySmith”, [“dancing”, “biking”, “cooking”]) person2 = … people = [person1, person2,..] I need to return a list of people sorted alpha…
How to simulate human keyboard input of a long text using Python?
I would like to simulate typing of huge text. I’ve tried to use pyautogui to do that, but I’t didn’t worked properly since the computer was not detecting the keys being pressed: I couldn’t think of another way to do that than using pynput.keyboard library, but as I have a huge text, th…
How to substract from each element in a matrix, with a condition
I have a matrix, and i don’t know the size, because the matrix was created from a dataframe. I have 2 arrays, min_cols and max_cols, first one is for each minimum from each column, and same with the max_cols. I want to recalculate each element from the columns, with this formula: Element[line][column] =…
convert 24 hour time (in string format) to time format
The time is given in string for eg “23:20”. However in my function I need to compare times for which I gotta convert these to time format I tried strptime() and it works with 12 hour format for eg when I enter “12:00PM” Answer For converting 24 hour format to a datetime.time object you…
How do I stop my scraper from hitting an error whenever it clicks the next button?
Hello so i’m trying to scrape next page on google shopping website. But i get an error whenever my scraper clicks the next button. It stops working when it loads the next page. Here’s my codeblock next_page = driver.find_element(By.XPATH, ‘//*[@id=”pnnext”]’) next_page.clic…
Updating A List Word Counter
I’m creating a program that counts letters. I created two dictionaries that both have the same word and, because they are the same exact word, both have the same counter. I want to know how to merge the two dictionaries so that it updates the counters as well, but I consistently receive the result ̶…
Extract first fields from struct columns into a dictionary
I need to create a dictionary from Spark dataframe’s schema of type pyspark.sql.types.StructType. The code needs to go through entire StructType, find only those StructField elements which are of type StructType and, when extracting into dictionary, use the name of parent StructField as key while value …