Since for the general case you are going to be returning a copy anyway, you may find yourself producing more readable code by using np.delete:

>>> a = np.arange(12).reshape(3, 4)
>>> np.delete(a, 2, axis=1)
array([[ 0,  1,  3],
       [ 4,  5,  7],
       [ 8,  9, 11]])
Answer from Jaime on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › select-all-columns-except-one-given-column-in-a-pandas-dataframe
Select all columns, except one given column in a Pandas DataFrame - GeeksforGeeks
July 15, 2025 - NumPy · Pandas · Practice · Django · Flask · Last Updated : 15 Jul, 2025 · DataFrame Data structure are the heart of Pandas library. DataFrames are basically two dimension Series object. They have rows and columns with rows representing the index and columns representing the content. Now, let's see how to Select all columns, except one given column in Pandas DataFrame in Python.
🌐
tribordo
tribordo.wordpress.com › 2013 › 06 › 18 › how-to-select-all-rows-except-one-in-python-with-numpy
How to select all rows except one in Python with Numpy | tribordo
June 18, 2013 - import numpy as np N = 5 A = np.arange(N * N).reshape(N, N) indices = np.arange(N) # exclude 3rd row A[indices != 2, :]
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.select.html
numpy.select — NumPy v2.3 Manual
Return elements from one of two arrays depending on condition. ... Try it in your browser! ... Beginning with an array of integers from 0 to 5 (inclusive), elements less than 3 are negated, elements greater than 3 are squared, and elements not meeting either of these conditions (exactly 3) are replaced with a default value of 42. >>> x = np.arange(6) >>> condlist = [x<3, x>3] >>> choicelist = [-x, x**2] >>> np.select(condlist, choicelist, 42) array([ 0, -1, -2, 42, 16, 25])
🌐
Medium
medium.com › @whyamit101 › how-to-select-all-columns-except-one-in-pandas-667a95ab2662
How to select all columns except one in pandas? | by why amit | Medium
April 13, 2025 - When we talk about “pandas all columns except one,” we refer to the practice of excluding a specific column from DataFrame operations, while retaining all other columns. How can I check which columns are in my DataFrame? You can use the columns attribute. For example, df.columns will return all the column names in your DataFrame. Can I exclude more than one column at a time?
🌐
Earth Data Science
earthdatascience.org › home
Slice (or Select) Data From Numpy Arrays | Earth Data Science - Earth Lab
September 23, 2019 - Numpy arrays are an efficient data structure for working with scientific data in Python. Learn how to use indexing to slice (or select) data from one-dimensional and two-dimensional numpy arrays.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.select.html
numpy.select — NumPy v2.5 Manual
When multiple conditions are satisfied, the first one encountered in condlist is used. ... The list of arrays from which the output elements are taken. It has to be of the same length as condlist. ... The element inserted in output when all conditions evaluate to False.
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › pandas › python-pandas-data-frame-exercise-58.php
Pandas: Select all columns, except one given column in a DataFrame - w3resource
September 6, 2025 - Original DataFrame col1 col2 col3 0 1 4 7 1 2 5 8 2 3 6 12 3 4 9 1 4 7 5 11 All columns except 'col3': col1 col2 0 1 4 1 2 5 2 3 6 3 4 9 4 7 5 ... Write a Pandas program to create a new DataFrame that excludes a specified column and then verify by listing the remaining column names. Write a Pandas program to drop one column from a DataFrame and then sort the remaining columns alphabetically. Write a Pandas program to select all columns except a given column using column filtering and then output the result.
🌐
Quora
quora.com › How-do-I-extract-specific-columns-from-a-NumPy-array-in-Python
How to extract specific columns from a NumPy array in Python - Quora
Answer (1 of 3): The simplest way is probably to use the standard indexing system with slicing. An element in a numpy array can be specified by using its indices normally such as arr[row, col] However, NumPy also allows for slicing, e.g. arr[1:4, 2], which returns the elements in column 2 (the ...
🌐
sqlpey
sqlpey.com › python › solved-how-to-select-all-columns-except-one-in-pandas
Solved: How to select all columns except one in pandas - …
December 5, 2024 - new_df = df[df.columns[~df.columns.isin(['b'])]] print(new_df) We can even run performance tests to see which method is the most efficient for larger DataFrames: import timeit setup_code = ''' import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(1000, 1000), columns=[f'col{i}' for i in range(1000)]) ''' drop_time = timeit.timeit('df.drop("col500", axis=1)', setup=setup_code, number=1000) loc_time = timeit.timeit('df.loc[:, df.columns != "col500"]', setup=setup_code, number=1000) print(f"Drop time: {drop_time}") print(f"Loc time: {loc_time}")
Top answer
1 of 2
5

Since the result's buffer will have a gap, compared to the original, it will have to be a copy. I believe delete takes different approaches depending on the inputs.

One approach is a boolean index, e.g.

ind = np.ones((10,), bool)
ind[n] = False
A1 = A[ind,:]

Another is to do the equivalent with index values

ind = range(n) + range(n+1:A.shape[0]] # using list concatenate
A1 = A[ind,:]

And as you note, using that index with take may be faster than direct indexing. I doubt if the difference is big, but I haven't timed it recently.

ind could also made by concatenation of 1d arrays. Alternatively, index the two parts, and concatenate them:

 np.concatenate([A[:n,:],A[n+1:],axis=0)

The inputs to concatenate are slices, but result is a copy.

 np.r_[0:n, n+1:A.shape[0]]

is a convenient way of generating the integer index list - but not necessarily a speed solution.

Why is the difference time difference between a view and a copy significant? If you do it a few times in the program, it shouldn't matter. If you do this deletion repeatedly, I'd question the larger program design. Could, you for example, accumulate the deletion indices, and perform the deletion step just once?


A few timings:

In [17]: arr=np.arange(1000)

In [18]: timeit arr[np.r_[:500,501:1000]].shape
10000 loops, best of 3: 55.7 us per loop

In [19]: timeit arr.take(np.r_[:500,501:1000]).shape
10000 loops, best of 3: 44.2 us per loop

In [20]: timeit np.r_[:500,501:1000]
10000 loops, best of 3: 36.3 us per loop

In [23]: timeit ind=np.ones(arr.shape[0],bool);ind[500]=False;arr[ind].shape
100000 loops, best of 3: 12.8 us per loop

Oops, the boolean index is faster in this test case.

Best yet:

In [26]: timeit np.concatenate((arr[:500],arr[501:])).shape
100000 loops, best of 3: 4.61 us per loop
2 of 2
2

I was able to come up with a function that uses np.take that runs faster than the list method.

def index_rows_by_exclusion_nptake(arr, i):
    """
    Return copy of arr excluding single row of position i using
    numpy.take function
    """
    return arr.take(range(i)+range(i+1,arr.shape[0]), axis=0)


%timeit index_rows_by_exclusion_nptake(x,1)
#The slowest run took 9.46 times longer than the fastest. This could mean that an intermediate result is being cached 
#100000 loops, best of 3: 2.95 µs per loop
🌐
Statology
statology.org › home › how to exclude columns in pandas (with examples)
How to Exclude Columns in Pandas (With Examples)
July 21, 2021 - import pandas as pd #create DataFrame df = pd.DataFrame({'points': [25, 12, 15, 14, 19, 23, 25, 29], 'assists': [5, 7, 7, 9, 12, 9, 9, 4], 'rebounds': [11, 8, 10, 6, 6, 5, 9, 12], 'blocks': [2, 3, 3, 5, 3, 2, 1, 2]}) #view DataFrame df points assists rebounds blocks 0 25 5 11 2 1 12 7 8 3 2 15 7 10 3 3 14 9 6 5 4 19 12 6 3 5 23 9 5 2 6 25 9 9 1 7 29 4 12 2 #select all columns except 'rebounds' and 'assists' df.loc[:, ~df.columns.isin(['rebounds', 'assists'])] points blocks 0 25 2 1 12 3 2 15 3 3 14 5 4 19 3 5 23 2 6 25 1 7 29 2 · Using this syntax, you can exclude any number of columns that you’d like by name. How to Add Rows to a Pandas DataFrame How to Add a Numpy Array to a Pandas DataFrame How to Count Number of Rows in Pandas DataFrame
🌐
ProjectPro
projectpro.io › recipes › select-elements-from-numpy-array-in-python
How to Select Columns in NumPy Array using np.select? -
February 22, 2024 - Selecting only the necessary columns helps in reducing the dimensionality of the data, which can improve computational efficiency and model performance.Selecting specific columns allows you to focus on cleaning and preprocessing only the relevant data, making the data cleaning process more efficient. np.select is a versatile function in NumPy that allows you to apply conditions element-wise on arrays and select values based on those conditions.
🌐
Stack Overflow
stackoverflow.com › questions › 54931632 › choosing-specific-rows-and-columns-from-numpy-array
python - Choosing specific rows and columns from numpy array - Stack Overflow
March 1, 2019 - Reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html ... Save this answer. Show activity on this post. You can select all rows and columns except one by applying conditions.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas select all columns except one column
Pandas Select All Columns Except One Column - Spark By {Examples}
March 27, 2024 - In this article, I will explain how to select all columns except one column in Pandas DataFrame. DataFrame is basically a two-dimension series object.
🌐
IncludeHelp
includehelp.com › python › select-all-elements-in-a-numpy-array-except-for-a-sequence-of-indices.aspx
Python - Select all elements in a NumPy array except for a sequence of indices?
December 28, 2023 - # Import numpy import numpy as np # Creating a numpy array arr = np.array([0,10,20,30,40,50,60]) # Display original array print("Original array:\n",arr,"\n") # List of indices ind = [1,3,5] # Selecting all elements except list of indices res = np.delete(arr, ind) # Display result print("Result:\n",res) In this example, we have used the following Python basic topics that you should learn: ... Is it possible to vectorize recursive calculation of a NumPy array where each element depends on the previous one? Python - How to return all the minimum indices in NumPy? Python - Assign 2D NumPy array column value as the values of the 1D array