Ask Your Question
0

How can a multidimensional array be converted to a Pandas dataframe?

asked 2023-03-01 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-04-14 07:00:00 +0000

nofretete gravatar image

A multidimensional array can be converted to a Pandas DataFrame using the pd.DataFrame() method.

Here is an example:

import pandas as pd
import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
df = pd.DataFrame(arr)
print(df)

This will output:

   0  1  2
0  1  2  3
1  4  5  6

In this example, we created a 2-dimensional array arr containing two rows and three columns. We then converted the array to a DataFrame using the pd.DataFrame() method and stored the result in the variable df. We then printed the DataFrame to the console using the print() function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-01 11:00:00 +0000

Seen: 8 times

Last updated: Apr 14 '21