Answers for "converting numpy array to dataframe"

3

convert array to dataframe python

np.random.seed(123)
e = np.random.normal(size=10)  
dataframe=pd.DataFrame(e, columns=['a']) 
print (dataframe)
          a
0 -1.085631
1  0.997345
2  0.282978
3 -1.506295
4 -0.578600
5  1.651437
6 -2.426679
7 -0.428913
8  1.265936
9 -0.866740

e_dataframe=pd.DataFrame({'a':e}) 
print (e_dataframe)
          a
0 -1.085631
1  0.997345
2  0.282978
3 -1.506295
4 -0.578600
5  1.651437
6 -2.426679
7 -0.428913
8  1.265936
9 -0.866740
Posted by: Guest on May-07-2020
5

dataframe from arrays python

import pandas as pd
df=pd.DataFrame({'col1':vect1,'col2':vect2})
Posted by: Guest on March-20-2020
10

convert dataframe to numpy array

>>> pd.DataFrame({"A": [1, 2], "B": [3, 4]}).to_numpy()
array([[1, 3],
       [2, 4]])
Posted by: Guest on February-21-2020
2

numpy arrauy to df

numpy_data = np.array([[1, 2], [3, 4]])
df = pd.DataFrame(data=numpy_data, index=["row1", "row2"], columns=["column1", "column2"])
print(df)
Posted by: Guest on September-10-2020
0

converting numpy array to dataframe

import numpy as np
import pandas as pd

# Creating a 2 dimensional numpy array
>>> data = np.array([[5.8, 2.8], [6.0, 2.2]])
>>> print(data)
>>> data
array([[5.8, 2.8],
       [6. , 2.2]])

# Creating pandas dataframe from numpy array
>>> dataset = pd.DataFrame({'Column1': data[:, 0], 'Column2': data[:, 1]})
>>> print(dataset)
   Column1  Column2
0      5.8      2.8
1      6.0      2.2
Posted by: Guest on September-17-2020
0

convert pandas dataframe to numpy dataframe

DataFrame.to_numpy(dtype=None, copy=False, na_value=<object object>)
Posted by: Guest on April-27-2021

Code answers related to "converting numpy array to dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language