Python Forum
TypeError: 'method' object is not subscriptable
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'method' object is not subscriptable
#1
Hi

The code is:
import pandas as pd
import quandl
import math

df = quandl.get('FINRA/FORF_TLLTD')

df['PCT']= df['ShortVolume']/df['TotalVolume']*100
df = df[['ShortVolume','TotalVolume', 'PCT']]
forecast_col = 'ShortVolume'
df.fillna(-99999, inplace= True)
forecast_out = int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift[-forecast_out]
df.dropna(inplace=True)
print(df.head())
And the error i am getting is
Error:
Traceback (most recent call last): File "C:/Program Files/PycharmProjects/code examples/code practice.py", line 28, in <module> df['label'] = df[forecast_col].shift[-forecast_out] TypeError: 'method' object is not subscriptable

Solved

i use [] instead () here .shift[-forecast_out]
Reply
#2
Hi, thanks for sharing the solution you found!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NoneType' object is not subscriptable shane1236 9 7,127 Aug-06-2020, 05:16 AM
Last Post: irvinborder
  TypeError: 'Series' object cannot be interpreted as an integer evelynow 2 17,602 Sep-11-2019, 02:43 PM
Last Post: timmahoney
  TypeError: expected string or bytes-like object twinpiques 1 25,680 May-06-2019, 08:29 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020