1np.random.seed(123)
2e = np.random.normal(size=10)
3dataframe=pd.DataFrame(e, columns=['a'])
4print (dataframe)
5 a
60 -1.085631
71 0.997345
82 0.282978
93 -1.506295
104 -0.578600
115 1.651437
126 -2.426679
137 -0.428913
148 1.265936
159 -0.866740
16
17e_dataframe=pd.DataFrame({'a':e})
18print (e_dataframe)
19 a
200 -1.085631
211 0.997345
222 0.282978
233 -1.506295
244 -0.578600
255 1.651437
266 -2.426679
277 -0.428913
288 1.265936
299 -0.866740
1import pandas as pd
2
3#initialize a dataframe
4df = pd.DataFrame(
5 [[21, 72, 67],
6 [23, 78, 69],
7 [32, 74, 56],
8 [52, 54, 76]],
9 columns=['a', 'b', 'c'])
10
11#convert dataframe to numpy array
12arr = df.to_numpy()
13
14print('\nNumpy Array\n----------\n', arr)
1numpy_data = np.array([[1, 2], [3, 4]])
2df = pd.DataFrame(data=numpy_data, index=["row1", "row2"], columns=["column1", "column2"])
3print(df)
1>>> df = pd.DataFrame({"A": [1, 2], "B": [3.0, 4.5]})
2>>> df.to_numpy()
3array([[1. , 3. ],
4 [2. , 4.5]])
5