如何将新元素'NEW'添加到numpy数组?

时间:2015-11-26 18:50:13

标签: python numpy

如何将新元素'NEW'添加到numpy数组features

df = pd.DataFrame(df_scaled)
df['NEW'] = minutes
features = np.append(features, 'NEW', 1)
df.to_excel("A.xls", header=features[sorted_idx],index=False)

错误:

ValueError: all the input arrays must have same number of dimensions

1 个答案:

答案 0 :(得分:0)

我假设features是一维字符串数组。然后你可以这样做:

features =np.append(features,['New'])

但是如果您只想将DataFrame的标题作为数组,则可能更好:

features = df.columns.values