Map to List error: Series object not callable

Quantum Dreamer picture Quantum Dreamer · Aug 25, 2016 · Viewed 76.9k times · Source
from nsepy import get_history
from datetime import date
import datetime
import pandas as pd
import numpy as np
file = r'C:\Users\Raspberry-Pi\Desktop\Desktop\List.xlsx'
list = pd.read_excel(file)
list = list['SYMBOL']
start = date.today()-datetime.timedelta(days = 10)
end = date.today()
symb = get_history(symbol='INFY',start = start,end = end)
h = symb.tail(3).High.tolist()
l = symb.tail(3).Low.tolist()
print(type(h))
print(type(l))
x =  map(lambda a,b:a-b,h,l)
print(type(x))
x = list(x)

I am getting error:

series object not callable

and its pointing to x = list(x) line.

Answer

hpaulj picture hpaulj · Aug 25, 2016

list(x) normally means turn x into a list object. It's a function that creates a list object. But near the top you redefined list:

list = pd.read_excel(file)

Now list is now a pandas series object (as the error message says), and it does not function as a function, i.e. it is not callable, it cannot be used with ().

Use a different name for this object. Use a silly name like foo if you can't think of a better descriptor.