I have a list that contains sublists of two different types of items (for instance, cats and dogs). I also have a function chunk(list, n_sublists) that splits the list into n_sublists of equal size. Then, i’d like to create a final list that merges the chunked lists from each type. An example: I hope th…
Converting csv with several items to a json with several elements in Python
Hello I have been exploring Python to do a task in which I have the following csv file: My goal was to get a json with the following structure: I was looking at a suggestion on how to convert csv files to json using the following code However the reader is not identifying each item in the csv as an
ADD multiple Files to a docker but just RUN one of them
It’s just a theoretical question. Is there a way to run the docker but only run one specific script without changing the Dockerfile? Maybe with the docker run [container] command? Dockerfile: Theoretical Command: docker run docker-test main2.py Answer There is nothing “theoretical” about thi…
pyspark – How to define MapType for when/otherwise
I have a pyspark DataFrame with a MapType column that either contains the map<string, int> format or is None. I need to perform some calculations using collect_list. But collect_list excludes None values and I am trying to find a workaround, by transforming None to string similar to Include null values …
How can I make Objects communicate with each other in Python?
I am making a little project for Neurons on replit. I made a class called Neurons. I set connections = []. I created a function called connect() to connect two Neurons via synapses. If one neuron fires, all of the other Neurons in the connections list would receive the signal. How could I make two different O…
Grouping asynchronous functions to run
I have a code that outputs numbers from 1 to 10: Output: 1 2 3 4 5 6 7 8 9 10 It is noticeable that in the example above, 10 functions are simultaneously launched at once. How can I fix the code so that the number of concurrent launched functions main() is equal to count_group? That is, immediately the
Count how often values in a 2D array appear in a 3D array
I have one 2-dimensional numpy array and another 3D-dimensional array. For each number in the first array I would like to count how often this value or an extremer one appears in the second array (taking the 3rd dimension as comparison vector for each element in the first array). For 0 values the function sho…
Pandas slow to merge and convert to datetime
I have two columns of data in a DataFrame containing a date and a time. Both start as strings. I want them to end up merged as a single column in datetime format. The head of the DataFrame is: They are in a DF called df_flattened and has about 20k rows and the code I am currently using is: However,
list index out of range in for loop (2nd iteration)
In my programm I take some data (variable raw) out of a database and have to use it. When using print(raw) this gets displayed: (‘x1 y1 z1 nx2 y2 z2 nx3 y3 z3 nx4 y4 z4’,) (raw has over 450 elements so I shortened it) Now I have to get x1 and y1 and forward them to another module. To
Correct usage of numpy.vstack with python’s numba
I am currently trying to speed up some python code using numba. According to the documentation of numba, numpy.meshgrid is not supported but numpy.vstack is. So I replaced the meshgrid call by vstack which works fine when not using numba. It does not work, however, when using numba. Here is the code: And here…