Skip to content

Group branches in an XML tree with Python on a common field

I have a list of order details in a CSV, and want to join all items from the lines together on one order. Example date is: I want everything to be listed in an XML with the root as the Order Number, Child as the Line Number and Sub-Children as Item and Price. I want the output to look like:

Don’t have idea why those errors appears

Everything in this code looks right to me, but when i put some numbers that length is different than 2 or put a word, at the end of code an error appear right below “Good bye” How do i fix that? Thank you in advance. Code: Answer Your inputnumber function doesn’t always return two digits (so…

Checking If Position Exists in Nested List

I’m trying to solve a Python coding problem. Given a certain array containing only 1’s and 0’s I must write a program that returns an array following a few rules: Each 1 must be replaced with a 9 Each 0 must be replaced with the amount of 1’s in its immediate surroundings (above, below…

Matplotlib stacked histogram numpy.ndarray error

I am trying to make a stacked histogram using matplotlib by looping through the categories in the dataframe and assigning the bar color based on a dictionary. I get this error on the ax1.hist() call. How should I fix it? AttributeError: ‘numpy.ndarray’ object has no attribute ‘hist’ Re…

Python: Expand 2D array to multiple 1D arrays

Consider the followoing example from np.meshgrid docs: In my application, instead of x and y, I’ve 25 variables. To create a grid out of the 25 variables, one way would be: However, the code will look ugly and not modular w.r.t. the number of variables (since each variable is hard-coded). Therefore, I a…

Merge numpy arrays with different dimensions

I have a numpy array with shape (100,9,17,2). I need to transform it to (100,15,17,2) adding zeros in missing cells. I created a zeros(100,6,17,2) but I can’t merge them. Can you help me? Answer Use numpy’s concatenate function. The axis argument is the argument over which you want the dimensions …