Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'list','_AtIndexer' object is not callable PandaPy

mp = pd.read_csv("Stock price over the last 24 months of Adidas, Nike, and Puma.csv",index_col=0)
mr = pd.DataFrame()
# compute monthly returns
for s in mp.columns:
    date = mp.index[0]
    pr0 = mp[s][date] 
    for t in range(1,len(mp.index)):
        date = mp.index[t]
        pr1 = mp[s][date]
        ret = (pr1-pr0)/pr0
        mr.set_value(date,s,ret)
        pr0 = pr1

I try to predict the Stock price over the last 24 months of Adidas, Nike, and Puma buy using panda and I’m get error

 TypeError                                 Traceback (most recent call last)
Input In [60], in <cell line: 3>()
      8 pr1 = mp[s][date]
      9 ret = (pr1-pr0)/pr0
---> 10 mr.set_value(date,s,ret)
     11 pr0 = pr1

TypeError: 'list' object is not callable

PS: I try to solve by reading same error but i can’t solve this.
trying to use mr.at instead of set_value and i got another error

    TypeError                                 Traceback (most recent call last)
Input In [3], in <cell line: 5>()
     10 pr1 = mp[s][date]
     11 ret = (pr1-pr0)/pr0
---> 12 mr.at(date,s,ret)
     13 pr0 = pr1

TypeError: '_AtIndexer' object is not callable

please help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you should use .at like this:

mr.at[date,s]=ret

full code:

mp = pd.read_csv("Stock price over the last 24 months of Adidas, Nike, and Puma.csv",index_col=0)
mr = pd.DataFrame()
# compute monthly returns
for s in mp.columns:
    date = mp.index[0]
    pr0 = mp[s][date] 
    for t in range(1,len(mp.index)):
        date = mp.index[t]
        pr1 = mp[s][date]
        ret = (pr1-pr0)/pr0
        mr.at[date,s]=ret
        pr0 = pr1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading