I have created a multi-hierarchical index from frames that have been indexed by time:
original_thing
time day_1 day_2 day_3 day_4
2018-05-24 20:00:00 0 0 1 0
2018-05-25 00:00:00 0 0 0 1
2018-05-25 04:00:00 0 0 0 1
2018-05-25 08:00:00 0 0 0 1
resampled and aggregated the info as different objects and packed them into a list
DF_list = [original_thing, resampled_1, resampled_2]
using pandas concat with code that looks mostly like this:
thisthing = pandas.concat(DF_list, keys=range(len(DF_list), names=['one','time'], sort=True)
to get a Dataframe that looks like:
one time day_1 day_2 day_3 day_4
2 2018-05-24 00:00:00 0 0 1 0
1 2018-05-24 12:00:00 0 0 1 0
0 2018-05-24 20:00:00 0 0 1 0
0 2018-05-25 00:00:00 0 0 0 1
1 2018-05-25 00:00:00 0 0 0 1
2 2018-05-25 00:00:00 0 0 0 1
0 2018-05-25 04:00:00 0 0 0 1
0 2018-05-25 08:00:00 0 0 0 1
I would like to take the index 'one' and get:
one time id_1 id_2 id_3 day_...
2 2018-05-24 00:00:00 0 0 1 0
1 2018-05-24 12:00:00 0 1 0 0
0 2018-05-24 20:00:00 1 0 0 0
0 2018-05-25 00:00:00 1 0 0 1
1 2018-05-25 00:00:00 0 1 0 1
2 2018-05-25 00:00:00 0 0 1 1
0 2018-05-25 04:00:00 1 0 0 1
0 2018-05-25 08:00:00 1 0 0 1
where id_'#'
are the encoded indexes from 'one'
I've tried to encode it with:
conc_ohlc_dummies= pandas.get_dummies(conc_ohlc['one'], prefix= 'hours')
but am getting this error:
return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'one'
I have also tried to reindex it to eliminate the index values. Is there any way other than writing to csv and reopening to do this?
thanks all