5

I'm a beginner/Student and want to develop a prototype for a neural Network. I want to create a variable from a DataFrame-column, but I get an error I do not understand:

# take() does not accept boolean indexers
KeyError: "None of [Index(['Solar - Actual Aggregated [MW]'], dtype='object')] are in the [columns]"

I have seen a post which said that spaces in the column name are not good, but in the past I did not had a Problem with that.

import pandas as pd
import numpy as np

df = pd.read_csv("...Test_Trainingsdaten/03.06.19/Produziert%20Solar%20Wind_28-06-19.csv")

df.info()
# MTU                               96 non-null object
# Solar - Actual Aggregated [MW]    96 non-null int64


X = df[["MTU"]].values                               # works                 
Y = df[["Solar - Actual Aggregated [MW]"]].values    # error

With those two variables i wanted to create a simple machine learning model, but I don't know how to fix that error

Georgy
  • 12,464
  • 7
  • 65
  • 73
Ulia
  • 75
  • 1
  • 6
  • If I google this error, I see lots of questions on Stack Overflow with similar titles. Have you checked any of them? – Georgy Jul 02 '19 at 08:14
  • Yes I did, but I couldn't find something useful, or I'm just not smart enough – Ulia Jul 02 '19 at 08:18
  • what does `print(df.columns.tolist())` show? – EdChum Jul 02 '19 at 08:19
  • ['area', 'mtu', 'solar__-_actual_aggregated_[mw]', 'wind_offshore__-_actual_aggregated_[mw]', 'wind_onshore__-_actual_aggregated_[mw]'] – Ulia Jul 02 '19 at 08:50
  • I used a command i found online: df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '').str.replace(')', ''), it changed my column Name to: solar__-actual_aggregated_[mw], now it works to create the variable – Ulia Jul 02 '19 at 08:52
  • Does this answer your question? [KeyError: "None of \[\['', ''\]\] are in the \[columns\]" pandas python](https://stackoverflow.com/questions/51976930/keyerror-none-of-are-in-the-columns-pandas-python) – cottontail Feb 03 '23 at 09:55

0 Answers0