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
复制相似问题