3
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)

I am getting this error : AttributeError: 'numpy.ndarray' object has no attribute 'apply'

I have looked through this website and no solutions seems to work. I simply want to multiply the data by 1.3 in this series. Thank you

7
  • 1
    int_series * 1.3? Commented Jul 17, 2018 at 18:25
  • @RafaelC I was attempting to multiply every value in my list by 1.3. I used this method because supposedly it is supposed to convert the series into an int. Commented Jul 17, 2018 at 18:27
  • int_series * 1.3 does multiply every value in the series by 1.3 Commented Jul 17, 2018 at 18:30
  • @roganjosh Okay, but then do you know the reason for my error? Commented Jul 17, 2018 at 18:30
  • The reason is simple: there is no apply function in numpy arrays. There are, though, in pandas.Series objects, which you would have if you did filevalues.astype(int) instead of filevalues.values.astype(int) Commented Jul 17, 2018 at 18:32

2 Answers 2

1

There's two issues here.

  1. By taking .values you actually access the underlying numpy array; you no longer have a pandas.Series. numpy arrays do not have an apply method.
  2. You are trying to use apply for a simple multiplication, which will be orders of magnitude slower than using a vectorized approach.

See below:

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
Sign up to request clarification or add additional context in comments.

Comments

0

numpy.ndarray does not have the 'apply' attribute. https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.