我需要将时间序列数据写入influxdb。我正在获取数据,它是字典列表,具有3列datetime,int64和int64。将datetime字段作为DataFrame的索引,并尝试使用write_points写入influxdb。
代码段:
数据:
datad_list = [{'time':datetime.datetime(2012,12,29,21,3,5, 203020),'c':5456L,'m':263L},{'time':datetime.datetime(2012,12, 29,21,3,4,956438),'c':5451L,'m':263L},{'time': datetime.datetime(2012,12,29,21,3,4,704390),'c':5459L,'m': 263L},{'time':datetime.datetime(2012、12、29、21、3、4、451795), 'c':5476L,'m':263L},{'time':datetime.datetime(2012,12,29,21, 3,4,204375),'c':5477L,'m':263L},
try:
df = pd.DataFrame(datad_list, columns=['time', 'c', 'm'])
except:
print "Unexpected error:", sys.exc_info()[1]
df.set_index(pd.DatetimeIndex(df['time']), inplace=True)
df.drop('time',axis=1,inplace=True)
print(df)
client = DataFrameClient(host, port, USER, PASSWORD, DBNAME)
print("setting data: ")
try:
client.write_points(df, DBNAME, protocol='line', time_precision='ms')
except:
print "Unexpected error:", sys.exc_info()[1]
print("Querying data: ")
result = client.query("select * from pdbase")
print("Result: {0}".format(result))
输出:
c m
2012-12-29 21:03:05.203020 5456 263
2012-12-29 21:03:04.956438 5451 263
2012-12-29 21:03:04.704390 5459 263
2012-12-29 21:03:04.451795 5476 263
2012-12-29 21:03:04.204375 5477 263
设置数据:
Unexpected error: 'DataFrame' object has no attribute 'select_dtypes'
write_points引发异常
请让我知道我做错了什么。预先感谢。