csv-to-influxdb.py 522 B

1234567891011121314151617181920
  1. #!/usr/bin/env python3
  2. import pandas
  3. from influxdb import DataFrameClient
  4. d = pandas.read_csv('log.csv', header=None, names=('timestamp', 'sensor', 'watts'))
  5. d['timestamp'] = pandas.to_datetime(d['timestamp'],unit='s')
  6. d = d.set_index('timestamp')
  7. d = d[d.watts.notnull()]
  8. #sensors = d.pivot_table(index='timestamp', columns='sensor', values='watts')
  9. client = DataFrameClient(database='power')
  10. for key, df in d.groupby('sensor'):
  11. print(key)
  12. client.write_points(df, 'flukso', {'sensor': key}, batch_size=100000)