Machine Learning with Python

Machine Learning with Python
0
#1

Received this error while trying to develop some basic formulas for a data set I received from quandl

import pandas as pd
import quandl
quandl.ApiConfig.api_key = 'hZHwvnpEs36oB1Kk7VUX'
df = quandl.get("WIKI/GOOGL");

Imported programs quandl and pandas

df = df[["Adj. Open"], df["Adj. High"], df["Adj. Low"], df["Adj. Close"], df["Adj. Volume"]]

Setting up columns to be used

df['HL_change'] = (df[1] - df[2]) / df[2] * 100
df['open_high_pc'] = (df[0]- df[3]) / df[3] * 100

basic percent change formula for the columns I listed (High and low) ( Open, Close)

df = df[df[ 'Adj. Close','HL_change', 'open_high_pc', 'Adj. Volume']]

list of new columns I want to show to reflect the formulas I just created. Below is the error I received

Traceback (most recent call last):
  File "C:/Users/tylpe/PycharmProjects/Machine_learning.py/Machine_Learning.py", line 6, in <module>
    df = df[["Adj. Open"], df["Adj. High"], df["Adj. Low"], df["Adj. Close"], df["Adj. Volume"]]`

File "C:\Users\tylpe\AppData\Roaming\Python\Python37\site-packages\pandas\core\frame.py", line 2927, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\tylpe\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexes\base.py", line 2657, in get_loc
    return self._engine.get_loc(key)
  File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 110, in pandas._libs.index.IndexEngine.get_loc
TypeError: '(['Adj. Open'], Date`


Name: Adj. Close, Length: 3424, dtype: float64, Date
**2004-08-19    44659000.0**
**2004-08-20    22834300.0**
**2004-08-23    18256100.0**
**2004-08-24    15247300.0**
**2004-08-25     9188600.0**
**2004-08-26     7094800.0**`

Name: Adj. Volume, Length: 3424, dtype: float64)' is an invalid key
#2

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.