I have multiple csv-files each containing two columns. The first contains the timestamp and the second column contains a measurement value.
Lets assume the csv-file looks like this:
Date,Temperature (Celsius)
2018-07-24T20:45:31,28.86
2018-07-24T20:35:31,29.06
2018-07-24T20:25:31,29.19
2018-07-24T20:15:32,29.31
2018-07-24T20:05:31,29.48
2018-07-24T19:55:31,29.58
2018-07-24T19:45:31,29.82
2018-07-24T19:35:32,30.32
2018-07-24T19:25:31,31.00
and I import it like this:
df = pd.read_csv(csv-file, sep=',', header = 0, usecols=[0, 1], parse_dates=[0], infer_datetime_format=True)
dd = df.set_index('Date').T.to_dict()
I thought this would be convenient later, when I would search for the same key (same timestamp) in multiple files in order to merge them. However I cannot access the dictionary. The keys are recognised as timestamp.
dd.keys()
dict_keys([Timestamp('2018-07-24 20:45:31'), Timestamp('2018-07-24 20:35:31'), Timestamp('2018-07-24 20:25:31'), Timestamp('2018-07-24 20:15:32'), Timestamp('2018-07-24 20:05:31'), Timestamp('2018-07-24 19:55:31'), Timestamp('2018-07-24 19:45:31'), Timestamp('2018-07-24 19:35:32'), Timestamp('2018-07-24 19:25:31')])
How do I access the values?
dd["2018-07-24 20:45:31"]["Temperature (Celsius)"]
does not work, so I tried
dd[Timestamp("2018-07-24 20:45:31")]["Temperature (Celsius)"]
which does not work either.
I was wondering if it might be forbidden to use a timestamp as a key, but if not, than how do I access my data?