【发布时间】:2021-06-01 03:27:52
【问题描述】:
根据以下代码将多个ndarray 转换为df 时
import numpy as np
import pandas as pd
ls_a = ['TA', 'BAT', 'T']
xxx = ['xx', 'cc']
feature_no = len(ls_a)
windows_no = len(xxx)
sub_iti = np.repeat([['s1']], (feature_no * windows_no), axis=0).reshape(-1, 1)
tw = np.repeat([xxx], feature_no, axis=1).reshape(-1, 1)
col_iti = np.repeat([ls_a], windows_no, axis=0).reshape(-1, 1)
df=pd.DataFrame ({'sub_iti': sub_iti,'tw': tw,'col_iti': col_iti})
,编译器返回错误
ValueError: 如果使用所有标量值,则必须传递索引
基于OP,输入参数index如下
df=pd.DataFrame (
{'sub_iti': sub_iti,
'tw': tw,
'col_iti': col_iti},index=range(0,3*2) )
但是,编译器返回差异错误
例外:数据必须是一维的
我可以知道如何解决这个问题吗?
【问题讨论】:
-
您是否尝试过使用
pd.DataFrame.from_dict? pandas.pydata.org/pandas-docs/stable/reference/api/… -
感谢@swagless_monk 的建议,但它返回
ValueError: Must pass 2-d input