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.astype(int)
calculated_series = int_series.apply(lambda x: filevalues*1.3)
print(filevalues)
我得到了这个错误:AttributeError: 'numpy.ndarray' object has no attribute 'apply'
我已经浏览了这个网站,但似乎没有解决方案。在本系列中,我只想将数据乘以1.3。谢谢
发布于 2018-07-18 02:40:15
这里有两个问题。
.values
,您实际上访问了底层的numpy
数组;您不再拥有pandas.Series
。numpy
数组没有apply
方法。apply
进行简单的乘法,这将比使用矢量化方法慢一个数量级。如下所示:
import pandas as pd
import numpy as np
df = pd.DataFrame({'a': np.arange(1000, dtype=np.float64)})
print(type(df['a']))
# Gives pandas.core.series.Series
print(type(df['a'].values))
# Gives numpy.ndarray
# The vectorized approach
df['a'] = df['a'] * 1.3
发布于 2018-07-18 02:39:41
numpy.ndarray没有'apply‘属性。https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html
https://stackoverflow.com/questions/51388050
复制相似问题