Convert Numpy Array to Dataframe Last Updated : 14 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Converting a NumPy array into a Pandas DataFrame makes our data easier to understand and work with by adding names to rows and columns and giving us tools to clean and organize it.In this article, we will take a look at methods to convert a numpy array to a pandas dataframe. We will be discussing two such methods and implement them.Using pd.DataFrame()Using pd.DataFrame.from_records()Before we begin with the conversion, we need to create a NumPy array.Creating a NumPy ArrayThe below code imports the NumPy and Pandas libraries and creates a 2D NumPy array named "data" containing a matrix. Python import numpy as np import pandas as pd # Create a NumPy array data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(data) Output:[[1 2 3] [4 5 6] [7 8 9]]Methods 1: pd.DataFrame()The most straightforward method is to use the Pandas pd.DataFrame() constructor, passing the NumPy array as an argument. Python # Using pd.DataFrame() df1 = pd.DataFrame(data) # Display the DataFrame print(df1) Output: 0 1 2 0 1 2 3 1 4 5 6 2 7 8 9Specifying Column NamesYou can provide column names while creating the DataFrame using the columns parameter. Python #Specifying Column Names df2 = pd.DataFrame(data, columns=['col1', 'col2', 'col3']) # Display the DataFrame print(df2) Output: col1 col2 col3 0 1 2 3 1 4 5 6 2 7 8 9Customize Row and Column IndicesCustomize both row and column indices using the index and columns parameters. Python # Approach 3: Customizing Row and Column Indices df3 = pd.DataFrame(data, index=['row1', 'row2', 'row3'], columns=['col1', 'col2', 'col3']) # Display the DataFrame print(df3) Output: col1 col2 col3 row1 1 2 3 row2 4 5 6 row3 7 8 9Methods 2: pd.DataFrame.from_records()Another way is to use pd.DataFrame.from_records() method, which is particularly useful when dealing with structured data or records. Python # Using pd.DataFrame.from_records() df4 = pd.DataFrame.from_records(data, columns=['col1', 'col2', 'col3']) # Display the DataFrame print(df4) Output: col1 col2 col3 0 1 2 3 1 4 5 6 2 7 8 9 Comment More infoAdvertise with us Next Article Convert Numpy Array to Dataframe O oceanofknow6flv Follow Improve Article Tags : Geeks Premier League Pandas Numpy Geeks Premier League 2023 Similar Reads How to Convert a Dataframe Column to Numpy Array NumPy and Pandas are two powerful libraries in the Python ecosystem for data manipulation and analysis. Converting a DataFrame column to a NumPy array is a common operation when you need to perform array-based operations on the data. In this section, we will explore various methods to achieve this t 2 min read How to Convert NumPy Matrix to Array In NumPy, a matrix is essentially a two-dimensional NumPy array with a special subclass. In this article, we will see how we can convert NumPy Matrix to Array. Also, we will see different ways to convert NumPy Matrix to Array. Convert Python NumPy Matrix to an ArrayBelow are the ways by which we can 3 min read Convert Bytes To a Pandas Dataframe In Python, bytes are a built-in data type used to represent a sequence of bytes. They are immutable sequences of integers, with each integer typically representing a byte of data ranging from 0 to 255. Convert Bytes Data into a Python Pandas Dataframe?We can convert bytes into data frames using diff 4 min read How to convert NumPy array to list ? This article will guide you through the process of convert a NumPy array to a list in Python, employing various methods and providing detailed examples for better understanding. Convert NumPy Array to List There are various ways to convert NumPy Array to List here we are discussing some generally us 4 min read Convert Numpy Array To Xarray Xarray is a powerful Python library for working with labeled multi-dimensional arrays. In Python, NumPy provides basic data structures and APIs for working with raw ND arrays, but, in the real world, the data is more complex, in some cases, which are encoded. The data array maps to positions in spac 3 min read Convert Python List to numpy Arrays NumPy arrays are more efficient than Python lists, especially for numerical operations on large datasets. NumPy provides two methods for converting a list into an array using numpy.array() and numpy.asarray(). In this article, we'll explore these two methods with examples for converting a list into 4 min read Convert JSON to Pandas DataFrame When working with data, it's common to encounter JSON (JavaScript Object Notation) files, which are widely used for storing and exchanging data. Pandas, a powerful data manipulation library in Python, provides a convenient way to convert JSON data into a Pandas data frame. In this article, we'll exp 4 min read Convert CSV to Pandas Dataframe In this article, we will discuss how to convert CSV to Pandas Dataframe, this operation can be performed using pandas.read_csv reads a comma-separated values (csv) file into DataFrame. Example 1: In the below program we are going to convert nba.csv into a data frame and then display it. Python # imp 1 min read How To Convert Numpy Array To Tensor? We are given a NumPy array, and our task is to convert it into a TensorFlow tensor. This is useful when integrating NumPy-based data with TensorFlow pipelines, which support acceleration using GPU and TPU. For example, converting [[1, 2], [3, 4]] results in a TensorFlow object that looks like: Pytho 2 min read How to Convert Pandas DataFrame into a List? In this article, we will explore the process of converting a Pandas DataFrame into a List, We'll delve into the methods and techniques involved in this conversion, shedding light on the versatility and capabilities of Pandas for handling data structures in Python.Ways to convert Pandas DataFrame Int 7 min read Like