我有一个日期框架:
TV Radio Newspaper Sales
1 230.1 37.8 69.2 22.1
2 44.5 39.3 45.1 10.4
3 17.2 45.9 69.3 9.3
4 151.5 41.3 58.5 18.5
5 180.8 10.8 58.4 12.9
我需要创建两个NumPy数组。其中一个包含Sales
行内容,另一个包含TV
、Radio
和Newspaper
行。你知道吗
import numpy as np
first_arr = np.array(myDateFrame['Sales'].values) #It works
second_arr = np.array(myDateFrame['TV', 'Radio', 'Newspaper']) #It doesn't work
它给出以下错误:
error: KeyError: ('TV', 'Radio', 'Newspaper')
我哪里出错了?你知道吗
你可以做:
不需要调用
np.array()
。属性values
已经是NumPy数组。你知道吗还要注意双方括号
[['TV', 'Radio', 'Newspaper']].
您需要将多个列名作为列表提供,而不是作为单个参数提供。你知道吗我将使用as_matrix()方法:
相关问题 更多 >
编程相关推荐