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 9 months ago. Improve this question I’m trying to get the indeces of the items of my list but on one item it returns a wrong index. There are two numbers
Tag: indexing
Slice pandas row of a specific column using numpy boolean
The objective is to slice multiple pandas row of a specific column using a Numpy boolean. The following code should do the task However, I wonder whether the above code can be shortened further, especially these lines Currently, Pandas throw an error if I am to directly using Numpy boolean without converting to list Is there something I miss, or
How do I use indexing to swap letters from a text file, using two different lists?
I’m in the process of making an encrypting/decrypting code and here’s what I have so far… I’m essentially trying to modify a text file in 3 ways, paste it to another file, then use that file to decrpyt the text file, and place it inside of another file. The only real problem I’m having with doing so, is making one
How to set merge and normalize multple dataframes for pd.merge_as_of
I am trying to merge multiple dataframes using pd.merge_asof. They all contain 2 columns with datetime as index column and a variable column with floating values. They are not balanced in their indexes and times so I have to normalize the values. I can succesfully merge the dfs and normalize the values like this using Now what I want to
I’ve got an object that is basically an int with some extra properties. Can I coerce it into an int when it’s used as a list index?
Context: I’m making a game that happens in a maze made of square tiles and almost everything, from movement to attacks, involves directions, which are mostly used to index lists. Subtracting or adding to directions is an easy way to turn left or right, but I always have to check that they are still within bounds, and I would like
Issue w/ pandas.index.get_loc() when match is found, TypeError: (“‘>’ not supported between instances of ‘NoneType’ and ‘str'”, ‘occurred at index 1’)
Below is the example to reproduce the error: The desired output should be a list or array with the values [3,NaN,4,3]. The NaN because it does not satisfy the criteria. I checked the pandas references and it says that for cases when you do not have an exact match you can change the “method” to ‘fill’, ‘brill’, or ‘nearest’ to
How to use the value of a 2d array as an index to a 3d array in numpy?
I have a 2d array, A, with shape (n x m), where each element of the array at position (i,j) holds a third value k. I want to increment a 3d array with dimensions nxmxl at position (k,i,j) based on the 2d array value and position. So for example if How do you do this in numpy efficiently? Answer The
How to add elements of a 1D NumPy array to NumPy subarrays with the same index?
Let’s say I have a NumPy array a with shape (3, 5, 7) and a 1D NumPy array l with shape (3, 1). I want to add the 0th element of l to the 0th subarray in a, the 1st element of l to the 1st subarray of a, and the 2nd element of l to the 2nd and last
Numba: indexing a vector is giving an error
I started using python and numba recently. My problem is: I have a matrix (n rows and m columns).In a for loop I have to change the values of specific columns. Without numba, the code is running fine. But when I use njit(), it just crashes. Note: In my real project, each row don’t have the same values. This is
Matching datetime column in pandas with another datetime column and return index
I have two DataFrames – df1 and df2. Both of them contain a datetime column, say date1 and date2. I want to match each value of date1 column to date2 and store the index in a new column. I am trying the following code: but this line throws out following error: Can only compare identically-labeled series objects. I also tried