I need to create the new Dataframe from old df, that contains defined columns.
model_columns = ['dist', 'date_day', 'is_holiday', 'date_dayofweek', 'date_month',
'tech', 'cap', 'HEIGHT', 'AZIMUTH', 'x', 'y'] // and other columns
X_train = df_train[model_columns]
<class 'pandas.core.frame.DataFrame'>
Int64Index: 720384 entries, 0 to 285510
Data columns (total 18 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 ID 720384 non-null int64
1 date_ 720384 non-null datetime64[ns]
2 spd 720384 non-null float64
3 subs 720384 non-null float64
4 trf 720384 non-null float64
5 y 720384 non-null int64
6 x 720384 non-null int64
7 tech 720384 non-null int64
8 cap 720384 non-null float64
9 HEIGHT 720384 non-null float64
10 AZIMUTH 720384 non-null int64
11 date_m 720384 non-null period[M]
12 date_month 720384 non-null int64
13 day_dayofweek 720384 non-null int64
14 is_holiday 720384 non-null bool
15 date_dayofweek 720384 non-null int64
16 date_day 720384 non-null int64
17 dist 720384 non-null float64
dtypes: bool(1), datetime64[ns](1), float64(6), int64(9), period[M](1)
But I get error:
KeyError Traceback (most recent call last)
<ipython-input-129-4fc28e7d3d66> in <module>
----> 1 X_train = df_train[model_columns] # # take() does not accept boolean indexers
and
KeyError: "['y_100', 'y_30', 'y_200', 'x_100', 'xy_100', 'xy', 'y_500', 'xy_50', 'xy_200', 'x_30', 'x_200', 'xy_30', 'x_500'] not in index"
What I should do there? Probably there df has wrond index?