Skip to content
Advertisement

Tag: numpy

How to add 2D np array to front of 3D np array?

I have a 3D numpy array and I want to add a 2D np array of 0’s to the front of it. I want to add another array B so that: I’ve tried np.append(B,A) but it returns a 2D array. Answer You can do it using numpy.vstack and by reshaping your array. For instance: By the way, you can create

Creating a tumbling windows in python

Just wondering if there is a way to construct a tumbling window in python. So for example if I have list/ndarray , listA = [3,2,5,9,4,6,3,8,7,9]. Then how could I find the maximum of the first 3 items (3,2,5) -> 5, and then the next 3 items (9,4,6) -> 9 and so on… Sort of like breaking it up to sections

Delete values over the diagonal in a matrix with python

I have the next problem with a matrix in python and numpy given this matrix i want to obtain this: I was trying with np.diag() but doesnt works Thanks! Answer Use np.tril(a) to extract the lower triangular matrix. Refer this : https://docs.scipy.org/doc/numpy/reference/generated/numpy.tril.html

How to remove NaN on CSV?

I have a .csv file of a table consisting of 12 col and 30k rows. One of the col is ‘mentions’, some of the data are empty (NaN). I am trying to remove all the rows where mentions = NaN. I don’t want to fill it with new data. I just wanna remove those rows so they wont be part

Taking the min value of N last days

I have this data frame: I want to show the min value of n last days (say, n = 4), using Date column, excluding the value of current day. A similar solution has provided by jezrael. (That one calculates the mean, and not min.) Expected result: Answer Use similar solution like @Chris with custom lambda function in GroupBy.apply and last

Advertisement