Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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
–
–
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.
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.