For a more general answer (if you need to discard several columns):

import numpy
x =  numpy.array(data)[:,range(0,6)+range(7,18)]
Answer from nicolas on Stack Overflow
Discussions

python - How to create an array from two columns in pandas - Stack Overflow
0 create new column with an array from two other columns and test it in python pandas More on stackoverflow.com
🌐 stackoverflow.com
How can I assign multiple rows and columns of one array to the same rows and columns of another array in Python? - Stack Overflow
As the title says, how do I assign multiple rows and columns of one array to the same rows and columns of another array in Python? More on stackoverflow.com
🌐 stackoverflow.com
pandas - Python: How to assign elements of an array to multiple columns in DataFrame? - Stack Overflow
So, I have a function like below: def do_something(row, args): # doing something return arr where arr = array([1, 2, 3, 4, 5]) and in my main function, I have a pandas DataFrame object df... More on stackoverflow.com
🌐 stackoverflow.com
numpy - Putting multiple columns of data into one array, python - Stack Overflow
So I have a set of data which has a singular column for x data and multiple columns for y data, of the form. x_title y_title_1 y_title_2 y_title_3 .... y_title_n data_x1 data_y2 More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 2
1

You can convert your dataframe in this way:

import pandas as pd
import numpy as np

df = pd.DataFrame({0:[[2387, 1098], [1873, 6792],], 1:[0,1]})
arr = np.array(df.loc[:,0].to_list())
df2 = pd.DataFrame({0:arr[:,0], 1:arr[:,1], 2:df.loc[:,1]})
print(df2)

The result is:

      0     1  2
0  2387  1098  0
1  1873  6792  1

A second way to solve the problem (with a "moon" sample) is:

import sklearn
import sklearn.datasets

X, y = sklearn.datasets.make_moons()
pd.DataFrame({'x0':X[:,0], 'x1': X[:,1], 'y':y})

and the result is:

          x0        x1  y
0   0.981559  0.191159  0
1   0.967948 -0.499486  1
2   0.018441  0.308841  1
3  -0.981559  0.191159  0
4   0.967295  0.253655  0
..       ...       ... ..
95  0.238554 -0.148228  1
96  0.096023  0.995379  0
97  0.327699 -0.240278  1
98  0.900969  0.433884  0
99  1.981559  0.308841  1

[100 rows x 3 columns]

2 of 2
1

EDIT:

Maybe it looks strange but you can use .str[0] to get first column from lists in DataFrame.

import pandas as pd

df = pd.DataFrame({0:[[2387, 1098], [1873, 6792],], 1:[0,1]})

new_df = pd.DataFrame({
              0: df[0].str[0], 
              1: df[0].str[1], 
              2: df[1]
         })

print(new_df)

OLDER:

Using apply() with pandas.Series you can convert first column into new DataFrame with two columns

import pandas as pd

df = pd.DataFrame({0:[[2387, 1098], [1873, 6792],], 1:[0,1]})

new_df = df[0].apply(pd.Series)

print(new_df)

Result:

      0     1
0  2387  1098
1  1873  6792

And later you can assing them back to old `DataFrame

df[2] = df[1]       # move `[0,1,...]` to column 2
df[[0,1]] = new_df  # put `new_df` in columns 0,1

Result:

      0     1  2
0  2387  1098  0
1  1873  6792  1

Or you can copy column [0,1,...] from old df to new_df

import pandas as pd

df = pd.DataFrame({0:[[2387, 1098], [1873, 6792],], 1:[0,1]})

new_df = df[0].apply(pd.Series)
new_df[2] = df[1]

print(new_df)

🌐
GeeksforGeeks
geeksforgeeks.org › program-to-access-different-columns-of-a-multidimensional-numpy-array
Program to access different columns of a multidimensional Numpy array | GeeksforGeeks
November 1, 2020 - Since NumPy is a fast (High-performance) Python library for performing mathematical operations so it is preferred to work on NumPy arrays rather than nested lists. Method 1: Using numpy.array(). Approach : Im ... In this article, let's discuss how to swap columns of a given NumPy array.
🌐
Stack Overflow
stackoverflow.com › questions › 65158057 › how-can-i-assign-multiple-rows-and-columns-of-one-array-to-the-same-rows-and-col
How can I assign multiple rows and columns of one array to the same rows and columns of another array in Python? - Stack Overflow
As the title says, how do I assign multiple rows and columns of one array to the same rows and columns of another array in Python? I want to do the following: Kn[0, 0] = KeTrans[startPosRow, start...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.column_stack.html
numpy.column_stack — NumPy v2.5 Manual
>>> import numpy as np >>> a = np.array((1,2,3)) >>> b = np.array((4,5,6)) >>> np.column_stack((a,b)) array([[1, 4], [2, 5], [3, 6]])
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 29945874 › putting-multiple-columns-of-data-into-one-array-python
numpy - Putting multiple columns of data into one array, python - Stack Overflow
So I have a set of data which has a singular column for x data and multiple columns for y data, of the form. x_title y_title_1 y_title_2 y_title_3 .... y_title_n data_x1 data_y2 data_y3 data_y4 data_yn .... .... .... .... .... .... I am trying to graph the data, a different plot for each y_data_i, on the same graph. I am using numpy arrays, matplotlib and scipy.
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
You can use nested generators to create two-dimensional arrays, placing the generator of the list which is a string, inside the generator of all the strings. Recall that you can create a list of n rows and m columns using the generator (which ...
🌐
Stack Overflow
stackoverflow.com › questions › 29949756 › putting-multiple-columns-into-callable-sub-arrays-python
numpy - Putting multiple columns into callable sub arrays python - Stack Overflow
I have a set of data which is in columns, where the first column is the x values. How do i read this in? ... Save this answer. ... Show activity on this post. If you want to store both, x and y values you can do · Copyydat = np.zeros((data.shape[1]-1,data.shape[0],2)) # write the x data ydat[:,:,0] = data[:,0] # write the y data ydat[:,:,1] = data[:,1:].T · Edit: If you want to store only the y-data in the sub arrays you can simply do
🌐
freeCodeCamp
freecodecamp.org › news › multi-dimensional-arrays-in-python
Multi-Dimensional Arrays in Python – Matrices Explained with Examples
December 11, 2025 - To create a multi-dimensional array using NumPy, we can use the np.array() function and pass in a nested list of values as an argument. The outer list represents the rows of the array, and the inner lists represent the columns.
Top answer
1 of 2
5

Does something like this work?

import numpy as np

x = np.array([[1,2],[3,4]])

y = np.array([[5,6],[7,8]])

result

>>> x
array([[1, 2],
       [3, 4]])
>>> y
array([[5, 6],
       [7, 8]])
>>> x[:,1] + y[:,1]
array([ 8, 12])
>>> x[:, 1] += y[:, 1] # using +=
>>> x[:, 1]
array([ 8, 12])

Update:

I think this should work for you:

src = np.array([["a", "b"], ["c", "d"], ["e", "f"]], dtype='|S8')
src2 = np.array([["x"], ["y"], ["z"]], dtype='|S8')

def add_columns(x, y):
    return [a + b for a,b in zip(x, y)]

def update_array(source_array, col_num, add_col):
    temp_col = add_columns(source_array[:, col_num], add_col)
    source_array[:, col_num] = temp_col  
    return source_array

Result:

>>> update_array(src, 1, src2[:,0])
array([['a', 'bx'],
       ['c', 'dy'],
       ['e', 'fz']], 
      dtype='|S8')
2 of 2
1

When you need to debug this kind of thing, it's useful to break it down into simpler steps. Are you getting the slices wrong, adding two incompatible array types, adding two types but trying to stick the results into an incompatible type (using += when + is OK but = is not), or adding incompatible data values? Any one of those could raise a TypeError, so how do we know which one you're doing?

Well, just do them at a time and see:

Slicing:

>>> src[:, 1]
array(['b', 'd', 'f'], dtype='|S1')
>>> src[:, 1] = ['x', 'y', 'z']
>>> src
>>> array([['a', 'x'], ['c', 'y'], ['e', 'z']], dtype='|S1')

That's fine. What about adding?

>>> src + src2
TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'

So, we've already found the same error as your more complicated case, without the slicing, and without the +=, which makes things much easier to debug. Let's make it even simpler:

>>> s1, s2 = np.array('a'), np.array('b')
>>> s1 + s2
TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'

So even adding two 0D arrays fails! Can't get any simpler than that.

Maybe it's the data types. What happens if we use integers?

>>> n1, n2 = np.array(1), np.array(2)
>>> n1 + n2
3

And you can go all the way back to your original example, using integers instead of strings, and it still works fine:

>>> m1 = np.array([[1,2], [3,4], [5,6]])
>>> m2 = np.array([[7], [8], [9]])
>>> m1[:, 1] += m2[:, 0]
>>> array([[ 1,  9],
           [ 3, 12],
           [ 5, 15]])

That should make it obvious that the problem is with data types. So, what is the data type? Just print out the array and see what numpy thinks it is:

>>> src = numpy.array([["a", "b"], ["c", "d"], ["e", "f"]])
>>> src
array([['a', 'b'], ['c', 'd'], ['e', 'f']], dtype='|S1')

That '|S1' isn't one of the friendly data types you see in the User Guide section on Data types, it's a structure definition, as explained in the section on Structured arrays. What it means is a 1-character fixed length string.

And that makes the problem obvious: You can't add two 1-character fixed-length strings, because the result isn't a 1-character fixed-length string.

If you really want to make this work as-is, the simple solution is to leave them as Python strings:

>>> src = numpy.array([["a", "b"], ["c", "d"], ["e", "f"]], dtype=object)
>>> src2 = numpy.array([["x"], ["y"], ["z"]], dtype=object)    
>>> src[:, 1] += src2[:, 0]

No more TypeError.

Alternatively, if you explicitly give src a dtype of |S2, numpy will allow that, and the second character will just be blank. It won't let you add another |S1 into it, but you can loop in Python, or maybe find a complicated way to fix numpy into doing it for you. Either way, you're not getting any of the usual time performance benefits of numpy of course, but you are still getting the space performance benefits of using packed fixed-size cells.

But you might want to step back and ask what you're trying to get out of numpy here. What is your actual higher-level goal here? Most of the benefit of numpy comes from using strict C/Fortran-style data types that numpy knows how to work with—it can pack them in tightly, access them without an extra dereference (and without refcounting), operate on in various ways from multiplying to copying to printing without any help from Python, etc. But it can't do string manipulation. If you're trying to vectorize string manipulation, you're using the wrong library to do it. If you're just using numpy because someone said it's fast, well, that's true in many cases, but not in this one. If you're using numpy because some other code is handing you numpy data, but you don't want to treat it in a numpy way, there's nothing stopping you from converting it to pure Python data.

🌐
Medium
medium.com › @heyamit10 › numpy-add-column-guide-0427e394b333
NumPy Add Column Guide. I understand that learning data science… | by Hey Amit | Medium
March 6, 2025 - Make sure the number of rows matches between the original array and the new columns. No need to reshape if you’re adding multiple columns — as long as it’s already a 2D array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-1-d-arrays-as-columns-into-a-2-d-array-in-python
How to convert 1-D arrays as columns into a 2-D array in Python? - GeeksforGeeks
July 15, 2025 - This function takes a sequence of 1-D arrays and stack them as columns to make a single 2-D array. ... tup : [sequence of ndarrays] Tuple containing arrays to be stacked. The arrays must have the same first dimension.
🌐
Reddit
reddit.com › r/askprogramming › python: how to add two lists together so they make an array with 2 columns. ie having a list with height and a list with weight combining it to make a list with height|weight?
r/AskProgramming on Reddit: Python: How to add two lists together so they make an array with 2 columns. IE having a list with height and a list with weight combining it to make a list with Height|Weight?
October 18, 2021 -

Im currently trying to learn how to code and im learning with Python. I'm on arrays but I dont understand how to combine lists like this. What im doing just tacks on the second list to the end making one really long list thats 1 column. Also what is this process called when combining the two lists into seperate columns in one array?