how to convert an array to a dataframe in python code example
Example 1: 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
Example 2: convert dataframe to numpy array
>>> pd.DataFrame({"A": [1, 2], "B": [3, 4]}).to_numpy()
array([[1, 3],
[2, 4]])