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。谢谢
答案 0 :(得分:0)
numpy.ndarray没有'apply'属性。 https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html
答案 1 :(得分:0)
这里有两个问题。
.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