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

Question:

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

Asked By: Arkromikz

||

Answers:

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
Answered By: Clegane
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.