Python Forum
TypeError: list indices must be integers or slices, not str
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: list indices must be integers or slices, not str
#1
So I am new to python and I can't seem to find the error with this code, when I try to run I get the message "TypeError: list indices must be integers or slices, not str". My code is:

import pandas as pd
import quandl


df = quandl.get("WIKI/GOOGL", authtoken="X5A1-ewy2UCfkFVfGKuW")
df = [["Adj. Open","Adj. High","Adj. Low","Adj. Close","Adj. Volume",]]
df["HL_PCT"] = (df["Adj. High"] - df["Adj. Close"]) / df["Adj. Close"] * 100.0
df["PCT_change"] = (df["Adj. Close"] - df["Adj. Open"]) / df["Adj. Open"] * 100.0

df = df [["Adj. Close","HL_PCT","PCT_change","Adj. Volume"]]

print(df.head())
Any help would be appiciated Big Grin
Reply


Messages In This Thread
TypeError: list indices must be integers or slices, not str - by TheDovah7 - Mar-04-2018, 08:27 PM
Really need help with some code! - by TheDovah7 - Mar-05-2018, 05:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pandas] TypeError: list indices must be integers or slices, not str but type is int. cspower 4 852 Dec-30-2023, 09:38 AM
Last Post: Gribouillis
  monthly composite of LST comes out incorrect, with error "mean of empty slices" ns423 1 2,874 Mar-18-2018, 06:40 PM
Last Post: ns423
  Making indices and rearrranging list reidybwoykeon 2 3,464 May-18-2017, 06:57 PM
Last Post: reidybwoykeon

Forum Jump:

User Panel Messages

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