Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question Please use the selection description to write a program that displays the corresponding four …
Tag: list
Convert a pandas df to defaultdict and look for matching positive and negative numbers
I have a dataframe like this: What i want to do know i convert the df into a defaultdict and look for only the matching matching positive and negative numbers per id so i want my desired dict to look something like this: I try to do this below but i get this error: Any idea how to solve this
Can’t replace an array inside a tuple with another array of same size – Python
I have a list of tuples: I want to replace the second np.array of the first tuple with an array of the same length but filled with zeros: I have tried the following: But I get the: Any idea how to complete the replacement process ? Answer Tuples are immutable in Python, you cannot change values stored in it. …
Sorting list by the inner elements in Python?
How that list can be sorted by the inner list elements? I need a list at the final like that; It will check the first elements of the inner lists, if there are more than one “True”, it will check and sort the second elements. If there are the same numbers, than it will check the third elements. An…
how to combine three lists comprehension into one using only one for loop?
I have a list in range (1 to 31). The final list is l = [x, y, z] You can see my code, it is work fine using three for loops: The outputs is: I tried to do it using only one for loop. I got this error: I don’t know if I can do it or not. please help
Create list from columns and add column to dataframe python
I have this dataframe: and I would like to create col_list and add it to the dataframe such that it looks like this: I have tried this code but it doesn’t work: Answer Try this
How to process files based on their date in Python?
I have two sort of files, xml files and txt files. The files have a date in their name. If the date of the xml file matches the date of a txt file I want to open the txt file do some processing and write the output to a list. After that I want to change the xml file. Multiple
how can I split the elements of a list of binary numbers?
I’m trying to split the elements of a list of binary numbers as follows : bin_list=[‘000101111000′,’011110111011’] Expected result: bin_list=[[0,0,0,1,0,1,1,1,1,0,0,0],[0,1,1,1,1,0,1,1,1,0,1,1]] I think that would be a list of a list of integers what I’m trying to get?? I t…
Trying to find element in an array from which the sum of elements on the left side is equal to elements on the right. Could you optimise my approach?
I am getting all test cases but two, failing due to timeout. What are my options? Answer You can do something like that: The time-complexity of this is O(n)
extract value from a list of json in pyspark
I have a dataframe where a column is in the form of a list of json. I want to extract a specific value (score) from the column and create independent columns. I want to explode my result dataframe as: Answer Assuming you have your json looks like this You can read it, flatten it, then pivot it like so