I have a dictionary that looks like below
defaultdict(list, {'Open': ['47.47', '47.46', '47.38', ...], 'Close': ['47.48', '47.45', '47.40', ...], 'Date': ['2016/11/22 07:00:00', '2016/11/22 06:59:00','2016/11/22 06:58:00', ...]})
My goal is to convert this dictionary into a data framework and set the Date key values ββas the index of the data frame.
I can complete this task with the following commands
df = pd.DataFrame(dictionary, columns=['Date', 'Open', 'Close']) 0 Date Open Close 1 2016/11/22 07:00:00 47.47 47.48 2 2016/11/22 06:59:00 47.46 47.45 3 2016/11/22 06:58:00 47.38 47.38 df.index = df.Date Date Date Open Close 2016/11/22 07:00:00 2016/11/22 07:00:00 47.47 47.48 2016/11/22 06:59:00 2016/11/22 06:59:00 47.46 47.45 2016/11/22 06:58:00 2016/11/22 06:58:00 47.38 47.38
but then I have two Date columns, one of which is the index and the other is the original column.
Is there a way to set the index while converting the dictionary to dataframe without column matches, as shown below?
Date Close Open 2016/11/22 07:00:00 47.48 47.47 2016/11/22 06:59:00 47.45 47.46 2016/11/22 06:58:00 47.38 47.38
Thanks for reading this! :)
source share