2017-09-30 2 views
0

Ich habe dieses [3526 rows x 5 columns] DF, wo col0 ist Zeit, col1-col3 sind Tags und ist mein Wert.Schreiben Pandas DF mit Tags zu Influxdb

    0    1     2   3  4 
0  2017-09-29 22:41:51  10.2.95.5 C1195_LF470_SARF 0.0.1.1 11993 
1  2017-09-29 22:41:37  10.2.52.7 CF643_RCZ70_SARM 0.0.1.16 12102 
2  2017-09-29 22:41:39 10.2.102.7 C1345_BQS70_SARF 0.0.1.17 18173 
3  2017-09-29 22:41:41 10.2.23.212 CN165_FS470_SAR8 0.0.0.7 23525 
4  2017-09-29 22:41:38  10.2.96.4 CF832_UY570_SARM 0.0.1.4 6162 

Also, ich möchte diesen DF in Influxdb schreiben. Ich werde tun, ...

timeValues = df[ ['col0','col4'] ] 
tags  = { 'col1': df[['col1']], 'col2': df[['col2']], 'col3':df[['col3']] } 

dbConnDF = DataFrameClient(dbAddress, dbPort, dbUser, dbPassword, dbName) 
dbConnDF.write_points(dbName, tbName, timeValues, tags = tags) 

Danach erhalte ich den Fehler Must be DataFrame with Datetime or PeriodIndex.

Allerdings, wenn ich Zeile tun einfügen Zeile dies mit ...

dbConnQRY = InfluxDBClient(dbAddress, dbPort, dbUser, dbPassword, dbName) 
dbConnQRY.write_points(bodyDB) 

bodyDB = [{ "measurement": tbName, "tags": { "col1": col1, "col2": col2, "col3": col3 }, "time": col0, "fields": { "col4": col4 } }] ... bekomme ich keine Fehler überhaupt. Das Problem tritt auf, wenn ich versuche, den gesamten DF auf einmal einzufügen.

Wie kann ich influxdb sagen, dass col0 mein Index ist, um den Fehler zu vermeiden?

Danke!

Antwort

1
Create an index column for dataframe 
timeValues = df[ ['col4'] ] 
timeValues.index = df[ ['col0'] ] 

von

dbConnDF = DataFrameClient(dbAddress, dbPort, dbUser, dbPassword, dbName) 
dbConnDF.write_points(dbName, tbName, timeValues, tags = tags) 

gefolgt, dass die Indizierung Problem lösen soll.

Verwandte Themen