import numpy as np
import pandas as pd
import scipy.sparse as sparse

df = pd.DataFrame(np.arange(1,10).reshape(3,3))
arr = sparse.coo_matrix(([1,1,1], ([0,1,2], [1,2,0])), shape=(3,3))
df['newcol'] = arr.toarray().tolist()
print(df)

yields

   0  1  2     newcol
0  1  2  3  [0, 1, 0]
1  4  5  6  [0, 0, 1]
2  7  8  9  [1, 0, 0]
Answer from unutbu on Stack Overflow
🌐
Statology
statology.org › home › how to add a numpy array to a pandas dataframe
How to Add a Numpy Array to a Pandas DataFrame
June 10, 2021 - import numpy as np import pandas as pd #create pandas 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]}) #create NumPy array for 'blocks' blocks = np.array([2, 3, 1, 0, 2, 7, 8, 2]) #add 'blocks' array as new column in DataFrame df['blocks'] = blocks.tolist() #display the DataFrame print(df) points assists rebounds blocks 0 25 5 11 2 1 12 7 8 3 2 15 7 10 1 3 14 9 6 0 4 19 12 6 2 5 23 9 5 7 6 25 9 9 8 7 29 4 12 2
Discussions

What is the proper way to insert an array into a pandas data frame?
First off, why are you trying to do that in the first place? What is compelling you to insert a list like that as opposed to taking a different approach? More on reddit.com
🌐 r/learnpython
10
2
May 25, 2021
python - how to append numpy array to a pandas dataframe - Stack Overflow
I have trained a Logistic Regression classifier to predict whether a review is positive or negative. Now, I want to append the predicted probabilities returned by the predict_proba-function to my P... More on stackoverflow.com
🌐 stackoverflow.com
How can I store a numpy matrix in a pandas dataframe?
pd.DataFrame(data=numpy_data, index=[list of index labels], columns=[list of column labels]) More on reddit.com
🌐 r/datascience
6
0
January 31, 2022
Numpy array vs Pandas Dataframe
A DataFrame is specialized for tabular, that is, 2D data. So it provides much of the same functionality spreadsheet programs like Excel do and you'd largely use it for similar kinds of tasks. A NumPy array is a general-purpose n-D data structure. You can use it pretty much for any numerical computation task. Whether you should depends on if there's a more specialized data structure available that might be more convenient. And by the way, DataFrames use NumPy arrays internally. More on reddit.com
🌐 r/learnpython
14
37
August 6, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › convert-numpy-array-to-dataframe
Convert Numpy Array to Dataframe - GeeksforGeeks
April 14, 2025 - The most straightforward method is to use the Pandas pd.DataFrame() constructor, passing the NumPy array as an argument. ... You can provide column names while creating the DataFrame using the columns parameter.
🌐
Saturn Cloud
saturncloud.io › blog › converting-a-2d-numpy-array-to-dataframe-rows-a-comprehensive-guide
Converting a 2D Numpy Array to DataFrame Rows: A Guide | Saturn Cloud Blog
May 1, 2026 - Consistent Data Types: Ensure that the Numpy array has consistent data types for each column. If the shape of the array does not match the expected shape for DataFrame rows, a ValueError will occur. Handle this by reshaping or transposing the array. import pandas as pd import numpy as np data = np.array([[1, 2], ['John', 'Jane'], [25, 30]]) # Transpose the array to match the expected shape df = pd.DataFrame(data.T, columns=['ID', 'Name', 'Age']) print(df)
🌐
IncludeHelp
includehelp.com › python › add-numpy-array-as-column-to-pandas-dataframe.aspx
Python - Add NumPy array as column to Pandas dataframe
January 8, 2023 - To add NumPy array as column to Pandas dataframe, you can use toarray() which we will use to convert the NumPy array into an array that will be added to the dataframe as a new column.
🌐
Data to Fish
datatofish.com › numpy-array-to-pandas-dataframe
How to Convert a NumPy Array to a pandas DataFrame
import numpy as np array = np.array([[500, 10, 1], [1000, 12, 0]]) You can then convert it to a DataFrame like this: import pandas as pd columns = ["salmon", "pufferfish", "shark"] df = pd.DataFrame(array, columns=columns) print(df) print(type(df)) The output of this code should look like this: ...
Find elsewhere
🌐
Appdividend
appdividend.com › converting-numpy-array-to-pandas-dataframe
How to Convert Numpy Array to Pandas DataFrame
November 24, 2025 - When we convert this array to a DataFrame, the named fields will serve as the column names, while each tuple is represented as a row within the DataFrame. When you convert a 1D structured array, each field becomes a column of the DataFrame. ...
🌐
Arab Psychology
scales.arabpsychology.com › home › how can i add a numpy array to a pandas dataframe?
How Can I Add A Numpy Array To A Pandas DataFrame?
April 23, 2024 - Finally, use the “concat” method to add the new DataFrame to the existing one. This will result in a new column being added to the DataFrame containing the data from the numpy array.
🌐
Reddit
reddit.com › r/learnpython › what is the proper way to insert an array into a pandas data frame?
r/learnpython on Reddit: What is the proper way to insert an array into a pandas data frame?
May 25, 2021 -

I am doing something like this.

df = pd.DataFrame({
        'a':[1,1,1,1],
        'b':['foo','foo','bar','bar'],
        'c':[3,3,None,3],
        'd':['foo','foo',None,'bar']})

df.loc[2, ['c','d']] = list([3, ['bar','foo']])

Before:

   a    b    c     d
0  1  foo  3.0   foo
1  1  foo  3.0   foo
2  1  bar  NaN  None
3  1  bar  3.0   bar

After:

   a    b    c           d
0  1  foo  3.0         foo
1  1  foo  3.0         foo
2  1  bar  3.0  [bar, foo]
3  1  bar  3.0         bar

But I get the following warning:

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.

I've always gotten this message and just ignored it, but I want to do thing correctly so when this deprecation take place in the future I don't get caught out. How should I go about this so I am doing it the correct way so I don't get this warning?

🌐
Reddit
reddit.com › r/datascience › how can i store a numpy matrix in a pandas dataframe?
r/datascience on Reddit: How can I store a numpy matrix in a pandas dataframe?
January 31, 2022 - Why you would want to do this instead of converting your data to columns being features and rows being observations, I don't know. ... import numpy as np import pandas as pd df = pd.DataFrame(columns = ['array'] #make dataframe a = np.array(range(1,10)).reshape(3,3) #3,3 matrix
🌐
Built In
builtin.com › articles › numpy-array-to-pandas-dataframe
How to Convert a NumPy Array to Pandas DataFrame | Built In
A NumPy array can be converted to a Pandas DataFrame through a variety of methods, including passing a NumPy array to pd.DataFrame and using the from_records() method.
🌐
TutorialsPoint
tutorialspoint.com › article › convert-a-numpy-array-to-pandas-dataframe-with-headers
Convert a NumPy array to Pandas dataframe with headers
May 30, 2023 - To create a Pandas DataFrame from a Numpy array with the headers, we can use the pandas DataFrame() method, by using the columns parameter we can specify the column headers while creating the dataframe object.
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › convert numpy array to pandas dataframe in python (2 examples)
Convert NumPy Array to pandas DataFrame in Python | Create from Matrix
October 4, 2022 - Example 1 demonstrates how to convert a NumPy array to a pandas DataFrame by columns. We first need to load the pandas library, if we want to use the corresponding functions: import pandas as pd # Import pandas library in Python
🌐
Saturn Cloud
saturncloud.io › blog › combining-numpy-arrays-into-a-pandas-dataframe-a-guide-for-data-scientists
Combining Numpy Arrays into a Pandas DataFrame: A Guide for Data Scientists | Saturn Cloud Blog
May 1, 2026 - These are not formats that Pandas can handle natively, so we need to do some preprocessing before we can convert them into a DataFrame. First, we need to import the necessary libraries. We’ll need Numpy for handling the arrays and Pandas for creating the DataFrame.
🌐
Medium
medium.com › practical-pandas › numpy-array-to-pandas-dataframe-3-ways-to-convert-a-numpy-array-to-dataframe-in-python-b5591404e129
Numpy Array to Pandas DataFrame: 3 Ways to Convert a Numpy Array to DataFrame in Python | by Dario Radečić | Practical Pandas | Medium
April 14, 2023 - If you want to convert Numpy Array to Pandas DataFrame, you have three options. The first two boil down to passing in a 1D or 2D Numpy array to a call to pd.DataFrame, and the last one leverages the built-in from_records() method.
🌐
Statology
statology.org › home › how to convert a numpy array to pandas dataframe
How to Convert a NumPy Array to Pandas DataFrame
September 17, 2021 - #convert array to DataFrame and specify rows & columns df = pd.DataFrame(data=data, index=["r1", "r2"], columns=["A", "B", "C", "D", "E"]) #print the DataFrame print(df) A B C D E r1 1 7 6 5 6 r2 4 4 4 3 1 · How to Add a Numpy Array to a Pandas DataFrame How to Drop the Index Column in Pandas Pandas: Select Rows Where Value Appears in Any Column
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-a-numpy-array-to-pandas-dataframe-with-headers
Convert a NumPy array to Pandas dataframe with headers - GeeksforGeeks
July 15, 2025 - import numpy as np import pandas as pd arr = np.array([[1, 2], [4, 5]]) print("Numpy array:") print(arr) # convert numpy array to dataframe df = pd.DataFrame(data = arr, index =["row1", "row2"], columns =["col1", "col2"]) print("\nPandas DataFrame: ") df · Output: Comment ·
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › convert numpy array to pandas dataframe
Convert NumPy Array to Pandas DataFrame - Spark By {Examples}
June 27, 2025 - To convert a NumPy array to a Pandas DataFrame, you can use the pd.DataFrame constructor provided by the Pandas library. We can convert the Numpy array to