Map to List error: Series object not callable

73,830

Solution 1

But I think you can omit map and use simple subtract and then convert to list:

symb = get_history(symbol='INFY',start = start,end = end)
print ((symb.tail(3).High - symb.tail(3).Low).tolist())

Also don't use variable list (reserved word in python) rather L (or something else):

L = pd.read_excel(file)
L = L['SYMBOL']

Sample:

import pandas as pd

symb = pd.DataFrame({'High':[8,9,7,5,3,4],'Low':[1,2,3,1,0,1]})
print (symb)
   High  Low
0     8    1
1     9    2
2     7    3
3     5    1
4     3    0
5     4    1

print ((symb.tail(3).High - symb.tail(3).Low).tolist())
[4, 3, 3]

EDIT:

I try simulate problem:

list = pd.DataFrame({'SYMBOL':['sss old','dd','old']})
print (list)
     SYMBOL
0  sss old
1       dd
2      old

list = list['SYMBOL']
print (list)
0    sss old
1         dd
2        old
Name: SYMBOL, dtype: object

print (type(list))
<class 'pandas.core.series.Series'>

x = [1,2,3]

#list is Series, not function
x = list(x)
print (x)
TypeError: 'Series' object is not callable

If change list to L, is important reopen python console, because still same error.

So this works perfectly:

df = pd.DataFrame({'SYMBOL':['sss old','dd','old']})
print (df)
     SYMBOL
0  sss old
1       dd
2      old

L = df['SYMBOL']
print (L)
0    sss old
1         dd
2        old
Name: SYMBOL, dtype: object

x = [1,2,3]
x = list(x)
print (x)
[1, 2, 3]

Solution 2

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.

Share:
73,830
Quantum Dreamer
Author by

Quantum Dreamer

Love Coding The Hard Way

Updated on June 30, 2020

Comments

  • Quantum Dreamer
    Quantum Dreamer almost 4 years
    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.

  • jezrael
    jezrael over 7 years
    I test it and for me it works. Do you use python 2 or python 3?
  • saikumarm
    saikumarm over 7 years
    I use python 2 and I am not a ardent programmer
  • jezrael
    jezrael over 7 years
    Do you use pandas? Can you test it?
  • saikumarm
    saikumarm over 7 years
    I do not use pandas
  • jezrael
    jezrael over 7 years
    Because in pandas list['SYMBOL'] means select column with name SYMBOL in DataFrame called list.
  • saikumarm
    saikumarm over 7 years
    the problem is not with list['SYMBOL'], but with reassigning list = list['SYMBOL']. the reference to the function list() is lost and now list i simple plain list
  • jezrael
    jezrael over 7 years
    Also if use read_excel and not parameter sheetname you get DataFrame. And if use list = list['SYMBOL'] you reassign DataFrame to Series (column called SYMBOL)
  • jezrael
    jezrael over 7 years
    I add it to answer.