Python 在panda数据帧中读取np数组

Python 在panda数据帧中读取np数组,python,pandas,numpy,Python,Pandas,Numpy,我有一组数据,看起来像: 12 , 12 , 12 , 12 #Data 1 16 , 16 , 16 , 16 #Data 2 3 , 3 , 3 , 3 #Data 3 3 , 3 , 3 , 3 .. 2 , 2 , 2 , 2 .. 9 , 9 , 9 , 9 .. 15 , 15 , 15 , 15 .. 并且数据是按行的,如图所示 现在,我需要在pandas中使用这些数据。问题是,以我有限的知识,panda按

我有一组数据,看起来像:

12 , 12 , 12 , 12    #Data 1
16 , 16 , 16 , 16    #Data 2
3  , 3  , 3  , 3     #Data 3
3  , 3  , 3  , 3     ..
2  , 2  , 2  , 2     ..
9  , 9  , 9  , 9     ..
15 , 15 , 15 , 15    ..
并且数据是按行的,如图所示

现在,我需要在
pandas
中使用这些数据。问题是,以我有限的知识,panda按列而不是按行读取数据

因此,(出于其他原因),我读取了
numpy
中的数据,并尝试将numpy数组读取为:

#!/usr/bin/env python3

import numpy as np
import pandas

names = ["A", "B", "C", "D", "E", "F", "G"]
data = np.genfromtxt("trial.dat", delimiter=',')
print(type(data))
print(data)
dataset = pandas.DataFrame(data=data, columns=names)
这就是:

python3 mwe.py 
<class 'numpy.ndarray'>
[[12. 12. 12. 12.]
 [16. 16. 16. 16.]
 [ 3.  3.  3.  3.]
 [ 3.  3.  3.  3.]
 [ 2.  2.  2.  2.]
 [ 9.  9.  9.  9.]
 [15. 15. 15. 15.]]
ValueError: Wrong number of items passed 4, placement implies 7
ValueError: Shape of passed values is (7, 4), indices imply (7, 7)
及 打印(数据集)

我得到:

class 'numpy.ndarray'>
[[12. 12. 12. 12.]
 [16. 16. 16. 16.]
 [ 3.  3.  3.  3.]
 [ 3.  3.  3.  3.]
 [ 2.  2.  2.  2.]
 [ 9.  9.  9.  9.]
 [15. 15. 15. 15.]]
      A     B     C     D
0  12.0  12.0  12.0  12.0
1  16.0  16.0  16.0  16.0
2   3.0   3.0   3.0   3.0
3   3.0   3.0   3.0   3.0
4   2.0   2.0   2.0   2.0
5   9.0   9.0   9.0   9.0
6  15.0  15.0  15.0  15.0
但在熊猫数据集中,我想要:

A    B 
12   16
12   16
12   16
12   16 
等,即沿行和阵列

那么,我怎样才能把np手册读给熊猫听呢

转置np_数组

dataset = pandas.DataFrame(data=data.T, columns=names)
dataset = pandas.DataFrame(data=data.T, columns=names)