Я бы очень признателен за вашу помощь здесь.
У меня получен этот результат из притока дБ.Это на самом деле словарь:
{u'current': [[0.03341725795376516, u'2018-10-10T12:41:27Z']], u'voltage': [[12.95246814679179, u'2018-10-10T12:41:27Z']], u'temperature': [[0.035324635690852216, u'2018-10-10T12:41:27Z']], u'tags': {u'product': u'00000000000000'}}
Другой пример:
u'data': {
u'measurement': u'telemetry'},
u'tags': {u'product_imei': u'000000000000000'},
u'current': [
[1.234, u'2016-01-01T00:00:00Z'], [2.234, u'2016-01-01T04:00:00Z'], [3.234, u'2016-01-01T08:00:00Z'], [1.234, u'2016-01-01T12:00:00Z'], [2.345, u'2016-01-01T16:00:00Z'], [2.678, u'2016-01-01T20:00:00Z'], [2.91, u'2016-01-02T00:00:00Z'], [2.345, u'2016-01-02T04:00:00Z'], [2.678, u'2016-01-02T08:00:00Z'], [2.91, u'2016-01-02T12:00:00Z'], [2.345, u'2016-01-02T16:00:00Z'], [2.678, u'2016-01-02T20:00:00Z'], [2.91, u'2016-01-03T00:00:00Z']
],
u'voltage': [
[14.243, u'2016-01-01T00:00:00Z'], [14.723, u'2016-01-01T04:00:00Z'], [14.826, u'2016-01-01T08:00:00Z'], [13.284, u'2016-01-01T12:00:00Z'], [12.345, u'2016-01-01T16:00:00Z'], [12.678, u'2016-01-01T20:00:00Z'], [12.91, u'2016-01-02T00:00:00Z'], [12.345, u'2016-01-02T04:00:00Z'], [12.678, u'2016-01-02T08:00:00Z'], [12.91, u'2016-01-02T12:00:00Z'], [12.345, u'2016-01-02T16:00:00Z'], [12.678, u'2016-01-02T20:00:00Z'], [12.91, u'2016-01-03T00:00:00Z']
],
u'temperature': [
[21.345, u'2016-01-01T00:00:00Z'], [None, u'2016-01-01T04:00:00Z'], [21.345, u'2016-01-01T08:00:00Z'], [None, u'2016-01-01T12:00:00Z'], [21.345, u'2016-01-01T16:00:00Z'], [None, u'2016-01-01T20:00:00Z'], [21.91, u'2016-01-02T00:00:00Z'], [None, u'2016-01-02T04:00:00Z'], [21.678, u'2016-01-02T08:00:00Z'], [None, u'2016-01-02T12:00:00Z'], [21.345, u'2016-01-02T16:00:00Z'], [None, u'2016-01-02T20:00:00Z'], [21.91, u'2016-01-03T00:00:00Z']
]
}
Я хотел бы иметь панду DataFrame, похожую на эту, используя python:
time current product voltage temperature
------------------------------------------------------------------
2016-01-01 00:00:00 1.234 000000000000000 14.243 21.345
2016-01-01 04:00:00 2.234 000000000000000 14.723
2016-01-01 08:00:00 3.234 000000000000000 14.826 21.345
2016-01-01 12:00:00 1.234 000000000000000 13.284
2016-01-01 16:00:00 2.345 000000000000000 12.345 21.345
2016-01-01 20:00:00 2.678 000000000000000 12.678
2016-01-02 00:00:00 2.910 000000000000000 12.910 21.910
2016-01-02 04:00:00 2.345 000000000000000 12.345
2016-01-02 08:00:00 2.678 000000000000000 12.678 21.678
2016-01-02 12:00:00 2.910 000000000000000 12.910
2016-01-02 16:00:00 2.345 000000000000000 12.345 21.345
2016-01-02 20:00:00 2.678 000000000000000 12.678
2016-01-03 00:00:00 2.910 000000000000000 12.910 21.910
Я уже попробовал очень, очень неэффективный способ сделать это, который на самом деле записывает строку за строкой.Слишком много времени.Я потратил целую вечность на тысячи единиц.
for i, line in enumerate(results['voltage']):
aux_dict = {}
for key in results.keys():
try:
results[key]
aux_dict[key] = results[key][i][0]
aux_dict['time'] = pd.to_datetime(line[1], infer_datetime_format=True)
output.append(aux_dict)
except:
"Column '" + key + "' does not have data."
continue
df = pd.DataFrame(output)
Заранее благодарен за помощь.