Altdaten übernehmen aus csv

Hello @DGR75,
You have a couple of options. The first is to use the csv.from() function like:

import "csv"

csvData =
    "
_time,region,host,_value
2018-05-08T20:50:00Z,east,A,15.43
2018-05-08T20:50:20Z,east,B,59.25
2018-05-08T20:50:40Z,east,C,52.62
"

csv.from(csv: csvData, mode: "raw")

Or for your data specifically:

import "csv"

csvData =
    "
Datum,Watt
30.06.2022,1.24
01.07.2022,1.46
02.07.2022,0.0
03.07.2022,0.0
04.07.2022,0.0
05.07.2022,0.0
06.07.2022,1.35
07.07.2022,3.83
"

csv.from(csv: csvData, mode: "raw")

However, please note that InfluxDB expects the timestamp to be in rfc3339 format. To change the format I suggest that you convert it to that format in excel or YYYY-MM-DD.
Then I’d suggest using the following functions to rename the columns and write the data to influxDB:

import "csv"

csvData =
    "
Datum,Watt
30.06.2022,1.24
01.07.2022,1.46
02.07.2022,0.0
03.07.2022,0.0
04.07.2022,0.0
05.07.2022,0.0
06.07.2022,1.35
07.07.2022,3.83
"

csv.from(csv: csvData, mode: "raw")
    |> rename(columns: {Datum: "_time", Watt: "_value"})
    |> experimental.set(o: {_field: "Watt", _measurement: "my measurement"})
    |> to(bucket: "<my bucket>") 

Alternatively, you can use the CLI to write CSV:

influx write -b example-bucket \
  -f path/to/example.csv \
  --header "#constant measurement,my-measurement" \
  --header "#datatype dateTime:2006-01-02,long"

If you plan on using the CLI you’ll want to set up a config too before using the config:

But again this solution you’ll need to change the timestamp to be in rfc3339 format.

Please let me know if you still need help and sorry for the delay.

Also you might be interested in:

As an example of how to format your timestamps with Flux.

1 Like