Department = input("Is there a list you would like to view")
readfile = pd.read_csv('6.csv')
filevalues= readfile.loc[readfile['Customer'].str.contains(Department, na=False), 'June-18\nQty']
filevalues = filevalues.fillna(int(0))
int_series = filevalues.values.ast
对于一个“普通”的Python类,我习惯于可以任意添加额外的属性。例如,我可以执行以下操作: # Create a class
class MyClass: pass
# Create an object of this class
my_object = MyClass()
# Add any attribute I want
my_object.my_new_attribute = "Hello world!"
# Now it has this attribute and I can use it:
print(my_object.my_new_attribute
在sklearn中实现的随机森林中有apply(X)函数-是否有与GBRT等效的函数?
编辑:
for estimator in gbrt.estimators_:
estimator.tree_.apply(X)
提供:
File "<pyshell#29>", line 2, in <module>
estimator.tree_.apply(Z)
AttributeError: 'numpy.ndarray' object has no attribute 'tree_'
尝试使用np.select或np.where对DataFrame列运行方法。无论采用哪种方法,我都会收到错误消息,说“对象没有'select‘属性(如果我使用np.where,则是'where’)。当我转换列并检查特定的列类型时,它会返回一个numpy.ndarray。根据numpy文档,np.where和np.select都应该在numpy数组上工作。 检查转换为numpy数组的Series上的类型,在检查类型后,我尝试该方法并收到错误: type(np.array(daily_std_df['Daily_Std']))
numpy.ndarray
typ
在我的实验中,我有一个numpy对象的实例,我需要设置它的__hash__方法。
我尝试过不同的方法(实际上看起来是一样的):
import numpy as np
x = np.array([1, 2, 3])
x.flags.writeable = False # set the array immutable
setattr(x, '__hash__', lambda self: 0) # doesn't work without self either
AttributeError: 'numpy.ndarray' object attri
当使用自定义类的numpy array时:
class TestClass:
active = False
如何使用内联掩码(布尔索引数组),如下所示:
直接尝试失败:
items = np.array([TestClass() for _ in range(10)])
items[items.active]
AttributeError: 'numpy.ndarray' object has no attribute 'active'
有什么建议吗?
我创建了子图,并且我想修改每个子图的xlim。为此,我编写了以下代码: import numpy as np
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 3, figsize=(20, 10))
for ax in np.nditer(axs, flags=['refs_ok']):
ax.set_xlim(left=0.0, right=0.5) 但是我得到了以下错误: AttributeError: 'numpy.ndarray' object has no attrib
下面是一个场景:
我有以下变量:
val = [('am', '<f8'), ('fr', '<f8')] # val is type numpy.recarray
am = [12.33, 1.22, 5.43, 15.23] # am is type numpy.ndarray
fr = [0.11, 1.23, 2.01, 1.01] # fr is type numpy.ndarray
我需要的是检测am = 12.33和am = 15.23的索引,一旦提取(在本例中索引是[0]和[
import scipy as sp
import numpy as np
a=sp.sparse.coo_matrix(np.random.randint(0,9,[4,5]))
b=sp.sparse.coo_matrix(np.random.randint(0,9,[4,2]))
sp.hstack([a,b]).toarray()
就是给我
AttributeError: 'numpy.ndarray' object has no attribute 'toarray'
你能帮我解决我的愚蠢错误吗?
我有点迷失了用海运relplot向我的标记添加标签的最佳方法。我在matplotlib文档中看到有一个axes.text()方法看起来是正确的方法,但是这个方法似乎并不存在。在这个意义上,seaborn的行为是否与matplotlib不同?正确的方法是什么? 错误: AttributeError: 'numpy.ndarray' object has no attribute 'text' 代码: line_minutes_asleep = sns.relplot(
x = "sleep_date",
y = "minu
我有一个二维的物体数组。我想迭代这个数组,并打印每个对象的一些属性。下面是我的代码:
import numpy as np
class example:
def __init__(self):
self.number = 1
a = example()
b = example()
c = example()
d = example()
array = np.array([[a,b],[c,d]],dtype=np.object)
for x in np.nditer(array,["refs_ok"]):
print x
错误消息:AttributeError
我试着用下面的代码.But来绘制子图,我正在获取'AttributeError: 'numpy.ndarray' object has no attribute 'boxplot'。
但更改plt.subplots(1,2)时,它正在用索引错误绘制方框图。
import matplotlib.pyplot as plt
import seaborn as sns
fig = plt.Figure(figsize=(10,5))
x = [i for i in range(100)]
fig , axes = plt.subplots(2,2)