Python 3.x 带标签的Python数据帧单行

Python 3.x 带标签的Python数据帧单行,python-3.x,pandas,Python 3.x,Pandas,我想将数据帧设置为: import pandas as pd data = ["X", "Y", "Z", "A", "B"] label = ['a','b','c','d','e'] df = pd.DataFrame(data, columns=label) print(df) 我越来越 a b c d e X Y Z A B 如何修复此问题以获得所需的数据帧 将其作为列表传递 ValueError: Shape of passed values is (1, 5), indices

我想将数据帧设置为:

import pandas as pd
data = ["X", "Y", "Z", "A", "B"]
label = ['a','b','c','d','e']
df = pd.DataFrame(data, columns=label)
print(df)
我越来越

a b c d e 
X Y Z A B

如何修复此问题以获得所需的数据帧

将其作为列表传递

ValueError: Shape of passed values is (1, 5), indices imply (5, 5)

如果大数据-将列表转换为
numpy数组
,然后:

计时

df = pd.DataFrame(np.array(data).reshape(-1, len(data)), columns=label)
print(df)
   a  b  c  d  e
0  X  Y  Z  A  B
df = pd.DataFrame(np.array(data).reshape(-1, len(data)), columns=label)
print(df)
   a  b  c  d  e
0  X  Y  Z  A  B
N = 100
data = ["X", "Y", "Z", "A", "B"] * N
label = ['a','b','c','d','e'] * N

In [30]: %timeit pd.DataFrame([data], columns=label)
10 loops, best of 3: 178 ms per loop

In [31]: %timeit pd.DataFrame(np.array(data).reshape(-1, len(data)), columns=label)
1000 loops, best of 3: 1.06 ms per loop

N = 1000

In [35]: %timeit pd.DataFrame([data], columns=label)
1 loop, best of 3: 1.7 s per loop

In [36]: %timeit pd.DataFrame(np.array(data).reshape(-1, len(data)), columns=label)
100 loops, best of 3: 3.83 ms per loop