pd.DataFrame([[12.794, 13.8],
[10.344, 13.356],
[10.521, 11.235],
[10.944, 14.978],
[10.374, 10.73]],
columns =['D6:4B:4C:E4:AE:29',
'ED:80:60:21:F4:ED',
'D1:7C:82:85:52:50',
'EA:CC:3B:08:72:06',
'C8:8F:56:44:4C:72'])
返回:
Traceback (most recent call last):
File "C:\", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "C:\", line 369, in __init__
arrays, columns = _to_arrays(data, columns, dtype=dtype)
File "C:\", line 6284, in _to_arrays
dtype=dtype)
File "C:\", line 6363, in _list_to_arrays
coerce_float=coerce_float)
File "C:\", line 6420, in _convert_object_array
'columns' % (len(columns), len(content)))
AssertionError: 5 columns passed, passed data had 2 columns
我有5列5行... 我尝试了3列和3行,并且有效。
请,我想澄清一下。 谢谢!
答案 0 :(得分:1)
我认为您正在寻找这个
d = np.array([[12.794, 13.8], [10.344, 13.356], [10.521, 11.235], [10.944, 14.978], [10.374, 10.73]])
columns =['D6:4B:4C:E4:AE:29', 'ED:80:60:21:F4:ED', 'D1:7C:82:85:52:50', 'EA:CC:3B:08:72:06', 'C8:8F:56:44:4C:72']
pd.DataFrame(dict(zip(columns, d)))
O / P:
C8:8F:56:44:4C:72 D1:7C:82:85:52:50 D6:4B:4C:E4:AE:29 EA:CC:3B:08:72:06 \
0 10.374 10.521 12.794 10.944
1 10.730 11.235 13.800 14.978
ED:80:60:21:F4:ED
0 10.344
1 13.356
说明:
zip
values
和header
的内容并转换为zip。然后将此内容传递给DataFrame
。
答案 1 :(得分:0)
您的数据结构形状不正确。您要输入5行和2列。我相信您希望2行5列。
arr=np.array([[12.794, 13.8], [10.344, 13.356], [10.521, 11.235], [10.944, 14.978], [10.374, 10.73]])
pd.DataFrame(np.reshape(np.array(arr),(2,5)),columns =['D6:4B:4C:E4:AE:29', 'ED:80:60:21:F4:ED', 'D1:7C:82:85:52:50', 'EA:CC:3B:08:72:06', 'C8:8F:56:44:4C:72'])